@anteros/core 0.0.10 → 0.0.11

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.
@@ -34,24 +34,24 @@ export function CheckIfArrayOfIds(action: string): any {
34
34
  }
35
35
  const originalMethod = descriptor.value;
36
36
  descriptor.value = async function (...args: any[]) {
37
-
37
+ let collection = args[0];
38
38
  let _ids = args[1];
39
39
  if (!Array.isArray(_ids)) {
40
- throw new AppError(`[${action}] IDs must be an array`, {
40
+ throw new AppError(`[${collection}] [${action}] IDs must be an array`, {
41
41
  code: 'INVALID_ARGUMENT',
42
42
  status: 400
43
43
  })
44
44
  }
45
45
  for (let id of _ids) {
46
46
  if (!ObjectId.isValid(id)) {
47
- throw new AppError(`[${action}] IDs must be an array of valid ObjectId`, {
47
+ throw new AppError(`[${collection}] [${action}] IDs must be an array of valid ObjectId`, {
48
48
  code: 'INVALID_ARGUMENT',
49
49
  status: 400
50
50
  })
51
51
  }
52
52
  }
53
53
  if (_ids.length === 0) {
54
- throw new AppError(`[${action}] IDs must be an array of at least one valid ObjectId`, {
54
+ throw new AppError(`[${collection}] [${action}] IDs must be an array of at least one valid ObjectId`, {
55
55
  code: 'INVALID_ARGUMENT',
56
56
  status: 400
57
57
  })
@@ -69,15 +69,16 @@ export function CheckInsertData(action: string): any {
69
69
  }
70
70
  const originalMethod = descriptor.value;
71
71
  descriptor.value = async function (...args: any[]) {
72
+ let collection = args[0];
72
73
  let data = args[1];
73
74
  if (action === 'insertOne') {
74
- if (!data) throw new AppError(`[${action}] Data is required`, {
75
+ if (!data) throw new AppError(`[${collection}] [${action}] Data is required`, {
75
76
  code: 'INVALID_ARGUMENT',
76
77
  status: 400
77
78
  })
78
79
  }
79
80
  if (action === 'insertMany') {
80
- if (!data) throw new AppError(`[${action}] Data is required`, {
81
+ if (!data) throw new AppError(`[${collection}] [${action}] Data is required`, {
81
82
  code: 'INVALID_ARGUMENT',
82
83
  status: 400
83
84
  })
@@ -94,9 +95,10 @@ export function CheckIfId(action: string): any {
94
95
  }
95
96
  const originalMethod = descriptor.value;
96
97
  descriptor.value = async function (...args: any[]) {
98
+ let collection = args[0];
97
99
  let _id = args[1];
98
100
  if (!ObjectId.isValid(_id)) {
99
- throw new AppError(`[${action}] ID must be a valid ObjectId`, {
101
+ throw new AppError(`[${collection}] [${action}] ID must be a valid ObjectId`, {
100
102
  code: 'INVALID_ARGUMENT',
101
103
  status: 400
102
104
  })
@@ -115,13 +117,14 @@ export function CheckFilter(): any {
115
117
  }
116
118
  const originalMethod = descriptor.value;
117
119
  descriptor.value = async function (...args: any[]) {
120
+ let collection = args[0];
118
121
  let filter = args[1];
119
122
  if (
120
123
  filter === null ||
121
124
  filter === undefined ||
122
125
  (typeof filter === 'object' && Object.keys(filter).length === 0)
123
126
  ) {
124
- throw new AppError(`[${propertyKey}] Filter is required and must not be empty`, {
127
+ throw new AppError(`[${collection}] [${propertyKey}] Filter is required and must not be empty`, {
125
128
  code: 'FILTER_REQUIRED',
126
129
  status: 400
127
130
  })
@@ -139,26 +142,27 @@ export function CheckBulkWriteOperations(): any {
139
142
  }
140
143
  const originalMethod = descriptor.value;
141
144
  descriptor.value = async function (...args: any[]) {
145
+ let collection = args[0];
142
146
  let operations = args[1];
143
147
  for (let operation of operations) {
144
- if (!operation) throw new AppError(`[bulkWrite] Operation is required`, {
148
+ if (!operation) throw new AppError(`[${collection}] [bulkWrite] Operation is required`, {
145
149
  code: 'INVALID_ARGUMENT',
146
150
  status: 400
147
151
  })
148
152
  if (Object.hasOwn(operation, 'insertOne')) {
149
- if (!operation.insertOne.document) throw new AppError(`[bulkWrite] Document is required`, {
153
+ if (!operation.insertOne.document) throw new AppError(`[${collection}] [bulkWrite] Document is required`, {
150
154
  code: 'INVALID_ARGUMENT',
151
155
  status: 400
152
156
  })
153
157
  }
154
158
  if (Object.hasOwn(operation, 'updateOne')) {
155
- if (!operation.updateOne.filter) throw new AppError(`[bulkWrite] Filter is required`, {
159
+ if (!operation.updateOne.filter) throw new AppError(`[${collection}] [bulkWrite] Filter is required`, {
156
160
  code: 'INVALID_ARGUMENT',
157
161
  status: 400
158
162
  })
159
163
  }
160
- if (Object.hasOwn(operation, 'updateOne')) {
161
- if (!operation.updateOne.filter) throw new AppError(`[bulkWrite] Filter is required`, {
164
+ if (Object.hasOwn(operation, 'updateMany')) {
165
+ if (!operation.updateMany.filter) throw new AppError(`[${collection}] [bulkWrite] Filter is required`, {
162
166
  code: 'INVALID_ARGUMENT',
163
167
  status: 400
164
168
  })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anteros/core",
3
3
  "module": "index.ts",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "description": "Anteros Core",
7
7
  "private": false,