File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,19 @@ export default async (
31
31
32
32
if ( data . id !== body . id ) {
33
33
res . statusCode = 400 ;
34
- return { Message : "replacing id is not allowed" } ;
34
+ return {
35
+ code : "BadRequest" ,
36
+ message : "replacing id is not allowed"
37
+ } ;
38
+ }
39
+
40
+ if ( req . headers [ "if-match" ] && req . headers [ "if-match" ] !== data . _etag ) {
41
+ res . statusCode = 412 ;
42
+ return {
43
+ code : "PreconditionFailed" ,
44
+ message :
45
+ "Operation cannot be performed because one of the specified precondition is not met."
46
+ } ;
35
47
}
36
48
37
49
return collection . documents . replace ( body ) ;
Original file line number Diff line number Diff line change @@ -26,5 +26,17 @@ export default async (
26
26
return { } ;
27
27
}
28
28
29
+ if ( req . headers [ "if-match" ] ) {
30
+ const data = collection . document ( body . id ) . read ( ) ;
31
+ if ( data && req . headers [ "if-match" ] !== data . _etag ) {
32
+ res . statusCode = 412 ;
33
+ return {
34
+ code : "PreconditionFailed" ,
35
+ message :
36
+ "Operation cannot be performed because one of the specified precondition is not met."
37
+ } ;
38
+ }
39
+ }
40
+
29
41
return collection . documents . upsert ( body ) ;
30
42
} ;
You can’t perform that action at this time.
0 commit comments