@aeriajs/core 0.0.222 → 0.0.223
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.js +3 -1
- package/dist/context.mjs +3 -1
- package/dist/functions/insert.js +30 -17
- package/dist/functions/insert.mjs +32 -18
- package/package.json +8 -8
package/dist/context.js
CHANGED
package/dist/context.mjs
CHANGED
package/dist/functions/insert.js
CHANGED
|
@@ -45,24 +45,37 @@ const internalInsert = async (payload, context) => {
|
|
|
45
45
|
? what._id
|
|
46
46
|
: null;
|
|
47
47
|
let newId = docId;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
try {
|
|
49
|
+
if (!newId) {
|
|
50
|
+
const content = prepareCreate(what, context.description);
|
|
51
|
+
const now = new Date();
|
|
52
|
+
Object.assign(content, {
|
|
53
|
+
created_at: now,
|
|
54
|
+
updated_at: now,
|
|
55
|
+
});
|
|
56
|
+
newId = (await context.collection.model.insertOne(content)).insertedId;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
await context.collection.model.updateOne({
|
|
60
|
+
_id: newId,
|
|
61
|
+
}, {
|
|
62
|
+
$set: {
|
|
63
|
+
...what,
|
|
64
|
+
updated_at: new Date(),
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
56
68
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof mongodb_1.MongoServerError) {
|
|
71
|
+
switch (err.code) {
|
|
72
|
+
case 11000: return context.error(types_1.HTTPStatus.InternalServerError, {
|
|
73
|
+
code: types_1.ACError.UniquenessViolated,
|
|
74
|
+
});
|
|
75
|
+
default: throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
66
79
|
}
|
|
67
80
|
const inheritedContext = {
|
|
68
81
|
...context,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ObjectId } from "mongodb";
|
|
3
|
-
import { Result, HTTPStatus } from "@aeriajs/types";
|
|
2
|
+
import { ObjectId, MongoServerError } from "mongodb";
|
|
3
|
+
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
4
4
|
import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
|
|
5
5
|
import { traverseDocument } from "../collection/index.mjs";
|
|
6
6
|
import { get } from "./get.mjs";
|
|
@@ -39,23 +39,37 @@ const internalInsert = async (payload, context) => {
|
|
|
39
39
|
}
|
|
40
40
|
const docId = "_id" in what && what._id instanceof ObjectId ? what._id : null;
|
|
41
41
|
let newId = docId;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
try {
|
|
43
|
+
if (!newId) {
|
|
44
|
+
const content = prepareCreate(what, context.description);
|
|
45
|
+
const now = /* @__PURE__ */ new Date();
|
|
46
|
+
Object.assign(content, {
|
|
47
|
+
created_at: now,
|
|
48
|
+
updated_at: now
|
|
49
|
+
});
|
|
50
|
+
newId = (await context.collection.model.insertOne(content)).insertedId;
|
|
51
|
+
} else {
|
|
52
|
+
await context.collection.model.updateOne({
|
|
53
|
+
_id: newId
|
|
54
|
+
}, {
|
|
55
|
+
$set: {
|
|
56
|
+
...what,
|
|
57
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (err instanceof MongoServerError) {
|
|
63
|
+
switch (err.code) {
|
|
64
|
+
case 11e3:
|
|
65
|
+
return context.error(HTTPStatus.InternalServerError, {
|
|
66
|
+
code: ACError.UniquenessViolated
|
|
67
|
+
});
|
|
68
|
+
default:
|
|
69
|
+
throw err;
|
|
57
70
|
}
|
|
58
|
-
}
|
|
71
|
+
}
|
|
72
|
+
throw err;
|
|
59
73
|
}
|
|
60
74
|
const inheritedContext = {
|
|
61
75
|
...context,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.223",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"aeriaMain": "tests/fixtures/aeriaMain.js",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"mongodb-memory-server": "^9.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@aeriajs/builtins": "^0.0.
|
|
46
|
-
"@aeriajs/common": "^0.0.
|
|
47
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
48
|
-
"@aeriajs/http": "^0.0.
|
|
49
|
-
"@aeriajs/security": "^0.0.
|
|
50
|
-
"@aeriajs/types": "^0.0.
|
|
51
|
-
"@aeriajs/validation": "^0.0.
|
|
45
|
+
"@aeriajs/builtins": "^0.0.223",
|
|
46
|
+
"@aeriajs/common": "^0.0.129",
|
|
47
|
+
"@aeriajs/entrypoint": "^0.0.132",
|
|
48
|
+
"@aeriajs/http": "^0.0.156",
|
|
49
|
+
"@aeriajs/security": "^0.0.223",
|
|
50
|
+
"@aeriajs/types": "^0.0.111",
|
|
51
|
+
"@aeriajs/validation": "^0.0.144"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mongodb": "^6.5.0",
|