@loomcore/api 0.0.49 → 0.0.50
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.
|
@@ -3,6 +3,7 @@ import { Application } from 'express';
|
|
|
3
3
|
import { IUser, IUserContext, IEntity, IAuditable } from '@loomcore/common/models';
|
|
4
4
|
import { GenericApiService } from '../services/generic-api.service.js';
|
|
5
5
|
import { ApiController } from '../controllers/api.controller.js';
|
|
6
|
+
import { MultiTenantApiService } from '../services/multi-tenant-api.service.js';
|
|
6
7
|
declare function initialize(database: Db): void;
|
|
7
8
|
declare function createIndexes(db: Db): Promise<void>;
|
|
8
9
|
declare function createMetaOrg(): Promise<void>;
|
|
@@ -59,6 +60,14 @@ export declare class ProductService extends GenericApiService<IProduct> {
|
|
|
59
60
|
export declare class ProductsController extends ApiController<IProduct> {
|
|
60
61
|
constructor(app: Application, db: Db);
|
|
61
62
|
}
|
|
63
|
+
export declare class MultiTenantProductService extends MultiTenantApiService<IProduct> {
|
|
64
|
+
constructor(db: Db);
|
|
65
|
+
protected getAdditionalPipelineStages(): any[];
|
|
66
|
+
transformSingle(single: any): any;
|
|
67
|
+
}
|
|
68
|
+
export declare class MultiTenantProductsController extends ApiController<IProduct> {
|
|
69
|
+
constructor(app: Application, db: Db);
|
|
70
|
+
}
|
|
62
71
|
declare function getTestUser(): Partial<IUser>;
|
|
63
72
|
declare function configureJwtSecret(): void;
|
|
64
73
|
declare function loginWithTestUser(agent: any): Promise<string>;
|
|
@@ -9,6 +9,7 @@ import { AuthService } from '../services/auth.service.js';
|
|
|
9
9
|
import { GenericApiService } from '../services/generic-api.service.js';
|
|
10
10
|
import { ApiController } from '../controllers/api.controller.js';
|
|
11
11
|
import { entityUtils } from '@loomcore/common/utils';
|
|
12
|
+
import { MultiTenantApiService } from '../services/multi-tenant-api.service.js';
|
|
12
13
|
let db;
|
|
13
14
|
let collections = {};
|
|
14
15
|
let deviceIdCookie;
|
|
@@ -242,6 +243,49 @@ export class ProductsController extends ApiController {
|
|
|
242
243
|
super('products', app, productService, 'product', ProductSpec, PublicAggregatedProductSchema);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
246
|
+
export class MultiTenantProductService extends MultiTenantApiService {
|
|
247
|
+
constructor(db) {
|
|
248
|
+
super(db, 'products', 'product', ProductSpec);
|
|
249
|
+
}
|
|
250
|
+
getAdditionalPipelineStages() {
|
|
251
|
+
return [
|
|
252
|
+
{
|
|
253
|
+
$lookup: {
|
|
254
|
+
from: 'categories',
|
|
255
|
+
localField: 'categoryId',
|
|
256
|
+
foreignField: '_id',
|
|
257
|
+
as: 'category'
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
$unwind: {
|
|
262
|
+
path: '$category',
|
|
263
|
+
preserveNullAndEmptyArrays: true
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
];
|
|
267
|
+
}
|
|
268
|
+
transformSingle(single) {
|
|
269
|
+
if (single && single.category) {
|
|
270
|
+
const categoryService = new CategoryService(this.db);
|
|
271
|
+
single.category = categoryService.transformSingle(single.category);
|
|
272
|
+
}
|
|
273
|
+
return super.transformSingle(single);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export class MultiTenantProductsController extends ApiController {
|
|
277
|
+
constructor(app, db) {
|
|
278
|
+
const productService = new MultiTenantProductService(db);
|
|
279
|
+
const AggregatedProductSchema = Type.Intersect([
|
|
280
|
+
ProductSpec.fullSchema,
|
|
281
|
+
Type.Partial(Type.Object({
|
|
282
|
+
category: CategorySpec.fullSchema
|
|
283
|
+
}))
|
|
284
|
+
]);
|
|
285
|
+
const PublicAggregatedProductSchema = Type.Omit(AggregatedProductSchema, ['internalNumber']);
|
|
286
|
+
super('multi-tenant-products', app, productService, 'product', ProductSpec, PublicAggregatedProductSchema);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
245
289
|
function getTestUser() {
|
|
246
290
|
return testUser;
|
|
247
291
|
}
|