@loomcore/api 0.0.38 → 0.0.40
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.
|
@@ -32,10 +32,12 @@ export interface IProduct extends IEntity, IAuditable {
|
|
|
32
32
|
category?: ICategory;
|
|
33
33
|
}
|
|
34
34
|
export declare const CategorySchema: import("@sinclair/typebox").TObject<{
|
|
35
|
+
_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
35
36
|
name: import("@sinclair/typebox").TString;
|
|
36
37
|
}>;
|
|
37
38
|
export declare const CategorySpec: import("@loomcore/common/models").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
38
39
|
export declare const ProductSchema: import("@sinclair/typebox").TObject<{
|
|
40
|
+
_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
39
41
|
name: import("@sinclair/typebox").TString;
|
|
40
42
|
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
41
43
|
internalNumber: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -2,6 +2,7 @@ import { ObjectId } from 'mongodb';
|
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import jwt from 'jsonwebtoken';
|
|
4
4
|
import { Type } from '@sinclair/typebox';
|
|
5
|
+
import { TypeboxObjectId } from '@loomcore/common/validation';
|
|
5
6
|
import { JwtService } from '../services/jwt.service.js';
|
|
6
7
|
import { passwordUtils } from '../utils/password.utils.js';
|
|
7
8
|
import { AuthService } from '../services/auth.service.js';
|
|
@@ -174,14 +175,16 @@ function verifyToken(token) {
|
|
|
174
175
|
return JwtService.verify(token, JWT_SECRET);
|
|
175
176
|
}
|
|
176
177
|
export const CategorySchema = Type.Object({
|
|
178
|
+
_id: Type.Optional(TypeboxObjectId()),
|
|
177
179
|
name: Type.String(),
|
|
178
180
|
});
|
|
179
181
|
export const CategorySpec = entityUtils.getModelSpec(CategorySchema);
|
|
180
182
|
export const ProductSchema = Type.Object({
|
|
183
|
+
_id: Type.Optional(TypeboxObjectId()),
|
|
181
184
|
name: Type.String(),
|
|
182
185
|
description: Type.Optional(Type.String()),
|
|
183
186
|
internalNumber: Type.Optional(Type.String()),
|
|
184
|
-
categoryId:
|
|
187
|
+
categoryId: TypeboxObjectId({ title: 'Category ID' }),
|
|
185
188
|
});
|
|
186
189
|
export const ProductSpec = entityUtils.getModelSpec(ProductSchema, { isAuditable: true });
|
|
187
190
|
export const PublicProductSchema = Type.Omit(ProductSpec.fullSchema, ['internalNumber']);
|
|
@@ -402,6 +402,7 @@ export class GenericApiService {
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
async prepareDataForBatchUpdate(userContext, entities) {
|
|
405
|
+
console.log('--- DIAGNOSTICS: Executing prepareDataForBatchUpdate ---');
|
|
405
406
|
return Promise.all(entities.map(item => this.prepareEntity(userContext, item, false, true)));
|
|
406
407
|
}
|
|
407
408
|
async prepareEntity(userContext, entity, isCreate, allowId = false) {
|
|
@@ -417,7 +418,16 @@ export class GenericApiService {
|
|
|
417
418
|
}
|
|
418
419
|
let cleanedEntity = preparedEntity;
|
|
419
420
|
if (this.modelSpec) {
|
|
421
|
+
let entityId = null;
|
|
422
|
+
if (allowId) {
|
|
423
|
+
console.log(`_id is present and equals ${preparedEntity._id}`);
|
|
424
|
+
entityId = preparedEntity._id;
|
|
425
|
+
}
|
|
420
426
|
cleanedEntity = this.modelSpec.decode(preparedEntity);
|
|
427
|
+
if (allowId && entityId) {
|
|
428
|
+
console.log(`after decode, restoring _id to ${entityId}`);
|
|
429
|
+
cleanedEntity._id = entityId;
|
|
430
|
+
}
|
|
421
431
|
}
|
|
422
432
|
if (!this.modelSpec?.fullSchema) {
|
|
423
433
|
throw new ServerError(`Cannot prepare entity: No model specification with schema provided for ${this.pluralResourceName}`);
|