@things-factory/product-base 6.2.177 → 6.2.178
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-server/constants/index.d.ts +1 -0
- package/dist-server/constants/product.d.ts +21 -0
- package/dist-server/controllers/index.d.ts +0 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/middlewares/index.d.ts +0 -0
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/service/index.d.ts +20 -0
- package/dist-server/service/product/index.d.ts +5 -0
- package/dist-server/service/product/product-mutation.d.ts +16 -0
- package/dist-server/service/product/product-mutation.js +6 -6
- package/dist-server/service/product/product-mutation.js.map +1 -1
- package/dist-server/service/product/product-query.d.ts +28 -0
- package/dist-server/service/product/product-query.js +2 -2
- package/dist-server/service/product/product-query.js.map +1 -1
- package/dist-server/service/product/product-types.d.ts +151 -0
- package/dist-server/service/product/product-types.js +7 -8
- package/dist-server/service/product/product-types.js.map +1 -1
- package/dist-server/service/product/product.d.ts +112 -0
- package/dist-server/service/product/product.js +10 -12
- package/dist-server/service/product/product.js.map +1 -1
- package/dist-server/service/product/validate-product.d.ts +2 -0
- package/dist-server/service/product/validate-product.js +1 -2
- package/dist-server/service/product/validate-product.js.map +1 -1
- package/dist-server/service/product-bundle/index.d.ts +5 -0
- package/dist-server/service/product-bundle/product-bundle-mutation.d.ts +9 -0
- package/dist-server/service/product-bundle/product-bundle-mutation.js +2 -2
- package/dist-server/service/product-bundle/product-bundle-mutation.js.map +1 -1
- package/dist-server/service/product-bundle/product-bundle-query.d.ts +12 -0
- package/dist-server/service/product-bundle/product-bundle-query.js +2 -2
- package/dist-server/service/product-bundle/product-bundle-query.js.map +1 -1
- package/dist-server/service/product-bundle/product-bundle-types.d.ts +20 -0
- package/dist-server/service/product-bundle/product-bundle-types.js +6 -6
- package/dist-server/service/product-bundle/product-bundle-types.js.map +1 -1
- package/dist-server/service/product-bundle/product-bundle.d.ts +25 -0
- package/dist-server/service/product-bundle/product-bundle.js +3 -4
- package/dist-server/service/product-bundle/product-bundle.js.map +1 -1
- package/dist-server/service/product-bundle-setting/index.d.ts +5 -0
- package/dist-server/service/product-bundle-setting/product-bundle-setting-mutation.d.ts +10 -0
- package/dist-server/service/product-bundle-setting/product-bundle-setting-mutation.js +4 -4
- package/dist-server/service/product-bundle-setting/product-bundle-setting-mutation.js.map +1 -1
- package/dist-server/service/product-bundle-setting/product-bundle-setting-query.d.ts +6 -0
- package/dist-server/service/product-bundle-setting/product-bundle-setting-query.js +2 -2
- package/dist-server/service/product-bundle-setting/product-bundle-setting-query.js.map +1 -1
- package/dist-server/service/product-bundle-setting/product-bundle-setting-types.d.ts +16 -0
- package/dist-server/service/product-bundle-setting/product-bundle-setting-types.js +4 -4
- package/dist-server/service/product-bundle-setting/product-bundle-setting-types.js.map +1 -1
- package/dist-server/service/product-bundle-setting/product-bundle-setting.d.ts +12 -0
- package/dist-server/service/product-bundle-setting/product-bundle-setting.js +2 -2
- package/dist-server/service/product-bundle-setting/product-bundle-setting.js.map +1 -1
- package/dist-server/service/product-combination/index.d.ts +5 -0
- package/dist-server/service/product-combination/product-combination-mutation.d.ts +9 -0
- package/dist-server/service/product-combination/product-combination-mutation.js +2 -2
- package/dist-server/service/product-combination/product-combination-mutation.js.map +1 -1
- package/dist-server/service/product-combination/product-combination-query.d.ts +11 -0
- package/dist-server/service/product-combination/product-combination-query.js +2 -2
- package/dist-server/service/product-combination/product-combination-query.js.map +1 -1
- package/dist-server/service/product-combination/product-combination-type.d.ts +20 -0
- package/dist-server/service/product-combination/product-combination-type.js +6 -6
- package/dist-server/service/product-combination/product-combination-type.js.map +1 -1
- package/dist-server/service/product-combination/product-combination.d.ts +33 -0
- package/dist-server/service/product-combination/product-combination.js +3 -3
- package/dist-server/service/product-combination/product-combination.js.map +1 -1
- package/dist-server/service/product-combination-setting/index.d.ts +5 -0
- package/dist-server/service/product-combination-setting/product-combination-setting-mutation.d.ts +11 -0
- package/dist-server/service/product-combination-setting/product-combination-setting-mutation.js +4 -4
- package/dist-server/service/product-combination-setting/product-combination-setting-mutation.js.map +1 -1
- package/dist-server/service/product-combination-setting/product-combination-setting-query.d.ts +14 -0
- package/dist-server/service/product-combination-setting/product-combination-setting-query.js +2 -2
- package/dist-server/service/product-combination-setting/product-combination-setting-query.js.map +1 -1
- package/dist-server/service/product-combination-setting/product-combination-setting-type.d.ts +18 -0
- package/dist-server/service/product-combination-setting/product-combination-setting-type.js +6 -6
- package/dist-server/service/product-combination-setting/product-combination-setting-type.js.map +1 -1
- package/dist-server/service/product-combination-setting/product-combination-setting.d.ts +22 -0
- package/dist-server/service/product-combination-setting/product-combination-setting.js +2 -2
- package/dist-server/service/product-combination-setting/product-combination-setting.js.map +1 -1
- package/dist-server/service/product-detail/index.d.ts +5 -0
- package/dist-server/service/product-detail/product-detail-mutation.d.ts +11 -0
- package/dist-server/service/product-detail/product-detail-mutation.js +18 -23
- package/dist-server/service/product-detail/product-detail-mutation.js.map +1 -1
- package/dist-server/service/product-detail/product-detail-query.d.ts +12 -0
- package/dist-server/service/product-detail/product-detail-query.js +2 -2
- package/dist-server/service/product-detail/product-detail-query.js.map +1 -1
- package/dist-server/service/product-detail/product-detail-types.d.ts +98 -0
- package/dist-server/service/product-detail/product-detail-types.js +6 -6
- package/dist-server/service/product-detail/product-detail-types.js.map +1 -1
- package/dist-server/service/product-detail/product-detail.d.ts +121 -0
- package/dist-server/service/product-detail/product-detail.js +7 -8
- package/dist-server/service/product-detail/product-detail.js.map +1 -1
- package/dist-server/service/product-detail-bizplace-setting/index.d.ts +5 -0
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.d.ts +8 -0
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.js +2 -2
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.js.map +1 -1
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.d.ts +11 -0
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.js +2 -2
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.js.map +1 -1
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.d.ts +24 -0
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.js +6 -6
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.js.map +1 -1
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting.d.ts +34 -0
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting.js +2 -2
- package/dist-server/service/product-detail-bizplace-setting/product-detail-bizplace-setting.js.map +1 -1
- package/dist-server/service/product-set/index.d.ts +5 -0
- package/dist-server/service/product-set/product-set-mutation.d.ts +39 -0
- package/dist-server/service/product-set/product-set-mutation.js +5 -5
- package/dist-server/service/product-set/product-set-mutation.js.map +1 -1
- package/dist-server/service/product-set/product-set-query.d.ts +12 -0
- package/dist-server/service/product-set/product-set-query.js +2 -2
- package/dist-server/service/product-set/product-set-query.js.map +1 -1
- package/dist-server/service/product-set/product-set-types.d.ts +18 -0
- package/dist-server/service/product-set/product-set-types.js +6 -6
- package/dist-server/service/product-set/product-set-types.js.map +1 -1
- package/dist-server/service/product-set/product-set.d.ts +22 -0
- package/dist-server/service/product-set/product-set.js +3 -4
- package/dist-server/service/product-set/product-set.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/index.d.ts +1 -0
- package/dist-server/utils/product-util.d.ts +3 -0
- package/package.json +4 -4
- package/server/service/product/product.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './product';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const PRODUCT_STATUS: {
|
|
2
|
+
ACTIVE: string;
|
|
3
|
+
DELETED: string;
|
|
4
|
+
INACTIVE: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const PRODUCT_SET_STATUS: {
|
|
7
|
+
ACTIVE: string;
|
|
8
|
+
DELETED: string;
|
|
9
|
+
INACTIVE: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const PRODUCT_BUNDLE_STATUS: {
|
|
12
|
+
ACTIVE: string;
|
|
13
|
+
DELETED: string;
|
|
14
|
+
INACTIVE: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const PRODUCT_COMBINATION_STATUS: {
|
|
17
|
+
ACTIVE: string;
|
|
18
|
+
ACTIVATED: string;
|
|
19
|
+
DELETED: string;
|
|
20
|
+
INACTIVE: string;
|
|
21
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare var migrations: any[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './product-combination-setting/product-combination-setting';
|
|
2
|
+
export * from './product-combination/product-combination';
|
|
3
|
+
export * from './product/product';
|
|
4
|
+
export * from './product-detail/product-detail';
|
|
5
|
+
export * from './product-bundle/product-bundle';
|
|
6
|
+
export * from './product-bundle-setting/product-bundle-setting';
|
|
7
|
+
export * from './product-detail-bizplace-setting/product-detail-bizplace-setting';
|
|
8
|
+
export * from './product-set/product-set';
|
|
9
|
+
export * from './product-combination/product-combination-type';
|
|
10
|
+
export * from './product-combination-setting/product-combination-setting-type';
|
|
11
|
+
export * from './product/product-types';
|
|
12
|
+
export * from './product-detail/product-detail-types';
|
|
13
|
+
export * from './product-bundle/product-bundle-types';
|
|
14
|
+
export * from './product-bundle-setting/product-bundle-setting-types';
|
|
15
|
+
export * from './product-detail-bizplace-setting/product-detail-bizplace-setting-types';
|
|
16
|
+
export * from './product-set/product-set-types';
|
|
17
|
+
export declare const entities: (typeof import("./product-detail-bizplace-setting/product-detail-bizplace-setting").ProductDetailBizplaceSetting | typeof import("./product-detail/product-detail").ProductDetail | typeof import("./product/product").Product | typeof import("./product-set/product-set").ProductSet | typeof import("./product-bundle-setting/product-bundle-setting").ProductBundleSetting | typeof import("./product-bundle/product-bundle").ProductBundle | typeof import("./product-combination-setting/product-combination-setting").ProductCombinationSetting | typeof import("./product-combination/product-combination").ProductCombination)[];
|
|
18
|
+
export declare const schema: {
|
|
19
|
+
resolverClasses: (typeof import("./product-detail/product-detail-mutation").ProductDetailMutation | typeof import("./product/product-mutation").ProductMutation | typeof import("./product/product-query").ProductQuery | typeof import("./product-bundle/product-bundle-mutation").ProductBundleMutation | typeof import("./product-bundle/product-bundle-query").ProductBundleQuery | typeof import("./product-bundle-setting/product-bundle-setting-mutation").ProductBundleSettingMutation | typeof import("./product-bundle-setting/product-bundle-setting-query").ProductBundleSettingQuery | typeof import("./product-detail/product-detail-query").ProductDetailQuery | typeof import("./product-detail-bizplace-setting/product-detail-bizplace-setting-mutation").ProductDetailBizplaceSettingMutation | typeof import("./product-detail-bizplace-setting/product-detail-bizplace-setting-query").ProductDetailBizplaceSettingQuery | typeof import("./product-set/product-set-mutation").ProductSetMutation | typeof import("./product-set/product-set-query").ProductSetQuery | typeof import("./product-combination/product-combination-query").ProductCombinationQuery | typeof import("./product-combination/product-combination-mutation").ProductCombinationMutation | typeof import("./product-combination-setting/product-combination-setting-query").ProductCombinationSettingQuery | typeof import("./product-combination-setting/product-combination-setting-mutation").ProductCombinationSettingMutation)[];
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Product } from './product';
|
|
2
|
+
import { ProductMutation } from './product-mutation';
|
|
3
|
+
import { ProductQuery } from './product-query';
|
|
4
|
+
export declare const entities: (typeof Product)[];
|
|
5
|
+
export declare const resolvers: (typeof ProductMutation | typeof ProductQuery)[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Product } from './product';
|
|
2
|
+
import { NewProduct, ProductPatch } from './product-types';
|
|
3
|
+
export declare class ProductMutation {
|
|
4
|
+
createProduct(product: NewProduct, context: ResolverContext): Promise<Product>;
|
|
5
|
+
createProducts(products: NewProduct[], context: ResolverContext): Promise<Product[]>;
|
|
6
|
+
updateProduct(id: string, patch: ProductPatch, context: ResolverContext): Promise<Product>;
|
|
7
|
+
importMultipleProduct(patches: ProductPatch[], context: ResolverContext): Promise<Product[]>;
|
|
8
|
+
updateMultipleProduct(patches: ProductPatch[], context: ResolverContext): Promise<Product[]>;
|
|
9
|
+
linkProduct(productSetId: string, patches: ProductPatch[], context: ResolverContext): Promise<Boolean>;
|
|
10
|
+
deleteProduct(id: string, context: ResolverContext): Promise<Boolean>;
|
|
11
|
+
deleteProducts(ids: string[], context: ResolverContext): Promise<Boolean>;
|
|
12
|
+
undeleteProducts(ids: string[], context: ResolverContext): Promise<Boolean>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createProduct(product: any, context: ResolverContext): Promise<any>;
|
|
15
|
+
export declare function createProducts(products: any, context: ResolverContext): Promise<any>;
|
|
16
|
+
export declare function updateProduct(id: string, patch: any, context: any): Promise<Product>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ProductMutation = void 0;
|
|
4
|
+
exports.createProduct = createProduct;
|
|
5
|
+
exports.createProducts = createProducts;
|
|
6
|
+
exports.updateProduct = updateProduct;
|
|
4
7
|
const tslib_1 = require("tslib");
|
|
5
8
|
const promises_all_1 = tslib_1.__importDefault(require("promises-all"));
|
|
6
9
|
const type_graphql_1 = require("type-graphql");
|
|
@@ -144,6 +147,7 @@ let ProductMutation = class ProductMutation {
|
|
|
144
147
|
return true;
|
|
145
148
|
}
|
|
146
149
|
};
|
|
150
|
+
exports.ProductMutation = ProductMutation;
|
|
147
151
|
tslib_1.__decorate([
|
|
148
152
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
149
153
|
(0, type_graphql_1.Mutation)(returns => product_1.Product),
|
|
@@ -231,10 +235,9 @@ tslib_1.__decorate([
|
|
|
231
235
|
tslib_1.__metadata("design:paramtypes", [Array, Object]),
|
|
232
236
|
tslib_1.__metadata("design:returntype", Promise)
|
|
233
237
|
], ProductMutation.prototype, "undeleteProducts", null);
|
|
234
|
-
ProductMutation = tslib_1.__decorate([
|
|
238
|
+
exports.ProductMutation = ProductMutation = tslib_1.__decorate([
|
|
235
239
|
(0, type_graphql_1.Resolver)(product_1.Product)
|
|
236
240
|
], ProductMutation);
|
|
237
|
-
exports.ProductMutation = ProductMutation;
|
|
238
241
|
async function createProduct(product, context) {
|
|
239
242
|
var _a, _b, _c;
|
|
240
243
|
try {
|
|
@@ -289,7 +292,6 @@ async function createProduct(product, context) {
|
|
|
289
292
|
throw error;
|
|
290
293
|
}
|
|
291
294
|
}
|
|
292
|
-
exports.createProduct = createProduct;
|
|
293
295
|
async function createProducts(products, context) {
|
|
294
296
|
const { resolve, reject } = await promises_all_1.default.all(products.map(product => createProduct(product, context)));
|
|
295
297
|
if (reject.length) {
|
|
@@ -298,7 +300,6 @@ async function createProducts(products, context) {
|
|
|
298
300
|
}
|
|
299
301
|
return resolve;
|
|
300
302
|
}
|
|
301
|
-
exports.createProducts = createProducts;
|
|
302
303
|
async function updateProduct(id, patch, context) {
|
|
303
304
|
var _a;
|
|
304
305
|
try {
|
|
@@ -356,5 +357,4 @@ async function updateProduct(id, patch, context) {
|
|
|
356
357
|
throw error;
|
|
357
358
|
}
|
|
358
359
|
}
|
|
359
|
-
exports.updateProduct = updateProduct;
|
|
360
360
|
//# sourceMappingURL=product-mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-mutation.js","sourceRoot":"","sources":["../../../server/service/product/product-mutation.ts"],"names":[],"mappings":";;;;AAAA,wEAAsC;AACtC,+CAAsE;AACtE,qCAAwC;AAExC,qEAA0F;AAC1F,uDAAmD;AACnD,6CAA4C;AAC5C,iDAAqD;AAErD,+CAAgD;AAChD,qEAAgE;AAChE,uFAIkD;AAClD,4DAAuD;AACvD,uCAAmC;AACnC,mDAA0D;AAC1D,yDAAoD;AAG7C,IAAM,eAAe,GAArB,MAAM,eAAe;IAGpB,AAAN,KAAK,CAAC,aAAa,CA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S,EAAE;YACnB,MAAM,IAAA,wCAAsB,EAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;YACpE,MAAM,IAAA,kCAAgB,EACpB,IAAI,EACJ;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,KAAK,CAAC,SAAS;oBACrB,OAAO,EAAE,iBAAO,CAAC,IAAI;oBACrB,KAAK,EAAE,OAAO,CAAC,EAAE;iBAClB;aACF,EACD,OAAO,CACR,CAAA;SACF;QAED,OAAO,OAAO,CAAA;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,KAAK,CAAA;KACZ;AACH,CAAC;AAvFD,sCAuFC","sourcesContent":["import promisesAll from 'promises-all'\nimport { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In, Repository } from 'typeorm'\n\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\nimport { Bizplace } from '@things-factory/biz-base'\nimport { logger } from '@things-factory/env'\nimport { getRepository } from '@things-factory/shell'\n\nimport { PRODUCT_STATUS } from '../../constants'\nimport { ProductDetail } from '../product-detail/product-detail'\nimport {\n createProductDetail,\n updateMultipleProductDetail,\n updateProductDetail\n} from '../product-detail/product-detail-mutation'\nimport { ProductSet } from '../product-set/product-set'\nimport { Product } from './product'\nimport { NewProduct, ProductPatch } from './product-types'\nimport { validateProduct } from './validate-product'\n\n@Resolver(Product)\nexport class ProductMutation {\n @Directive('@transaction')\n @Mutation(returns => Product)\n async createProduct(@Arg('product') product: NewProduct, @Ctx() context: ResolverContext): Promise<Product> {\n return await createProduct(product, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async createProducts(\n @Arg('products', type => [NewProduct]) products: NewProduct[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n return await createProducts(products, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => Product)\n async updateProduct(\n @Arg('id') id: string,\n @Arg('patch') patch: ProductPatch,\n @Ctx() context: ResolverContext\n ): Promise<Product> {\n return await updateProduct(id, patch, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async importMultipleProduct(\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n try {\n let results = []\n\n //// 1. Group and massage data based on sku for Product and Product Details.\n let massagedPatch = patches.reduce(function (acc, currentObj) {\n let existingParent = acc.find(itm => itm.sku == currentObj.sku)\n if (existingParent) {\n existingParent.productDetails = [\n ...existingParent.productDetails,\n new ProductDetail({ ...currentObj, childProductDetail: currentObj.childGtin })\n ]\n return acc\n } else {\n let newProduct = {\n ...currentObj,\n productDetails: [\n new ProductDetail({ ...currentObj, childProductDetail: currentObj.childGtin, isDefault: true })\n ]\n }\n return [...acc, newProduct]\n }\n }, [])\n\n //// 2. Update all Grouped Product data and Product Details Data\n for (let i = 0; i < massagedPatch.length; i++) {\n const patch: Product = massagedPatch[i]\n const result = await createProduct(patch, context)\n results.push({ ...result, cuFlag: '+' })\n }\n\n return results\n } catch (error) {\n throw error\n }\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async updateMultipleProduct(\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n try {\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const patch: NewProduct = _createRecords[i]\n const result = await createProduct(patch, context)\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const patch: ProductPatch = _updateRecords[i]\n const result = await updateProduct(patch.id, patch, context)\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n } catch (error) {\n throw error\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async linkProduct(\n @Arg('productSetId') productSetId: string,\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { tx } = context.state\n\n let productSet = await tx.getRepository(ProductSet).findOne({\n where: { id: productSetId },\n relations: ['domain', 'creator', 'updater', 'product']\n })\n\n let existingProductLink: any = productSet.product\n\n let newProductLink: Product[] = patches.reduce((acc, curr) => {\n if (!existingProductLink.find(itm => itm.id == curr.id)) {\n acc.push({ id: curr.id })\n }\n return acc\n }, [])\n\n let removeProductLink: Product[] = existingProductLink.reduce((acc, curr) => {\n if (!patches.find(itm => itm.id == curr.id)) {\n acc.push({ id: curr.id })\n }\n return acc\n }, [])\n\n if (newProductLink.length > 0) {\n for (let i = 0; i < newProductLink.length; i++) {\n const patch: Product = { ...newProductLink[i], productSet }\n await updateProduct(newProductLink[i].id, patch, context)\n }\n }\n\n if (removeProductLink.length > 0) {\n for (let i = 0; i < removeProductLink.length; i++) {\n const patch: Product = { ...removeProductLink[i], productSet: null }\n await updateProduct(removeProductLink[i].id, patch, context)\n }\n }\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteProduct(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx, user, domain } = context.state\n const productSetRepo: Repository<Product> = tx.getRepository(Product)\n const productSet = await productSetRepo.findOneBy({ domain: { id: domain.id }, id })\n\n await productSetRepo.save({\n ...productSet,\n status: PRODUCT_STATUS.DELETED,\n updater: user\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteProducts(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx, user } = context.state\n const productRepo = tx.getRepository(Product)\n\n await productRepo.update(\n {\n id: In(ids)\n },\n {\n deletedAt: new Date()\n }\n )\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async undeleteProducts(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { tx, user } = context.state\n const productRepo = tx.getRepository(Product)\n\n await productRepo.update(\n {\n id: In(ids)\n },\n {\n deletedAt: null\n }\n )\n\n return true\n }\n}\n\nexport async function createProduct(product: any, context: ResolverContext) {\n try {\n const { domain, user, tx } = context.state\n\n const productRepo: Repository<Product> = tx.getRepository(Product) || getRepository(Product)\n const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace) || getRepository(Bizplace)\n\n let bizplace: Bizplace\n if (product.bizplace?.id) {\n bizplace = await bizplaceRepo.findOneBy({ id: product.bizplace.id })\n } else if (context.state?.bizplace) {\n bizplace = context.state.bizplace\n } else {\n bizplace = await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n }\n\n if (product?.productRef?.id) {\n product.productRef = await productRepo.findOneBy({ id: product.productRef.id })\n }\n\n if (!product?.id) delete product.id\n\n await validateProduct(\n {\n ...product,\n bizplace,\n domain\n },\n context\n )\n\n if (product.uom) {\n product.primaryUnit = product.uom\n }\n\n if (product.uomValue) {\n product.primaryValue = product.uomValue\n }\n\n const result = await productRepo.save({\n ...product,\n bizplace,\n domain,\n creator: user,\n updater: user\n })\n\n let productDetails = product.productDetails\n if (!productDetails) {\n productDetails = [new ProductDetail({ ...product, product: result, isDefault: true })]\n if (productDetails[0].gtin == null || productDetails[0] == undefined) {\n productDetails[0].gtin = product.sku\n }\n }\n\n await updateMultipleProductDetail(result.id, productDetails, context)\n\n if (product.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: product.thumbnail,\n refType: Product.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n } catch (error) {\n throw error\n }\n}\n\nexport async function createProducts(products, context: ResolverContext) {\n const { resolve, reject } = await promisesAll.all(products.map(product => createProduct(product, context)))\n\n if (reject.length) {\n reject.forEach(({ name, message }) => logger.error(`${name}: ${message}`))\n\n return reject\n }\n\n return resolve\n}\n\nexport async function updateProduct(id: string, patch, context) {\n try {\n const { user, tx, domain } = context.state\n\n const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace)\n const productRepo: Repository<Product> = tx.getRepository(Product)\n const productDetailRepo: Repository<ProductDetail> = tx.getRepository(ProductDetail)\n\n let product = await productRepo.findOne({ where: { id }, relations: ['domain'] })\n\n let productDetail = await productDetailRepo.findOne({\n where: { product: { id }, isDefault: true },\n relations: ['domain']\n })\n\n if (patch.productRef && patch.productRef.id) {\n patch.productRef = await productRepo.findOne(patch.productRef.id)\n }\n\n let bizplace: Bizplace\n if (product.bizplace?.id) {\n bizplace = await bizplaceRepo.findOneBy({ id: product.bizplace.id })\n } else {\n bizplace = await bizplaceRepo.findOne({ where: { name: domain.name } })\n }\n\n await validateProduct(\n {\n ...product,\n ...patch,\n bizplace,\n domain\n },\n context\n )\n\n if (patch.uom) {\n product.primaryUnit = patch.uom\n }\n\n if (patch.uomValue) {\n product.primaryValue = patch.uomValue\n }\n\n product = await productRepo.save({\n ...product,\n ...patch,\n domain,\n updater: user\n })\n\n if (productDetail) {\n if (product.gtin) {\n delete product.gtin\n }\n productDetail = await updateProductDetail(\n productDetail.id,\n new ProductDetail({ ...product, ...patch, product }),\n context\n )\n } else {\n productDetail = await createProductDetail(\n new ProductDetail({ ...product, ...patch, product, isDefault: true }),\n context\n )\n }\n\n const productId = id\n if (patch.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [productId] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.thumbnail,\n refType: Product.name,\n refBy: product.id\n }\n },\n context\n )\n }\n\n return product\n } catch (error) {\n throw error\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"product-mutation.js","sourceRoot":"","sources":["../../../server/service/product/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Content":["import promisesAll from 'promises-all'\nimport { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In, Repository } from 'typeorm'\n\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\nimport { Bizplace } from '@things-factory/biz-base'\nimport { logger } from '@things-factory/env'\nimport { getRepository } from '@things-factory/shell'\n\nimport { PRODUCT_STATUS } from '../../constants'\nimport { ProductDetail } from '../product-detail/product-detail'\nimport {\n createProductDetail,\n updateMultipleProductDetail,\n updateProductDetail\n} from '../product-detail/product-detail-mutation'\nimport { ProductSet } from '../product-set/product-set'\nimport { Product } from './product'\nimport { NewProduct, ProductPatch } from './product-types'\nimport { validateProduct } from './validate-product'\n\n@Resolver(Product)\nexport class ProductMutation {\n @Directive('@transaction')\n @Mutation(returns => Product)\n async createProduct(@Arg('product') product: NewProduct, @Ctx() context: ResolverContext): Promise<Product> {\n return await createProduct(product, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async createProducts(\n @Arg('products', type => [NewProduct]) products: NewProduct[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n return await createProducts(products, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => Product)\n async updateProduct(\n @Arg('id') id: string,\n @Arg('patch') patch: ProductPatch,\n @Ctx() context: ResolverContext\n ): Promise<Product> {\n return await updateProduct(id, patch, context)\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async importMultipleProduct(\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n try {\n let results = []\n\n //// 1. Group and massage data based on sku for Product and Product Details.\n let massagedPatch = patches.reduce(function (acc, currentObj) {\n let existingParent = acc.find(itm => itm.sku == currentObj.sku)\n if (existingParent) {\n existingParent.productDetails = [\n ...existingParent.productDetails,\n new ProductDetail({ ...currentObj, childProductDetail: currentObj.childGtin })\n ]\n return acc\n } else {\n let newProduct = {\n ...currentObj,\n productDetails: [\n new ProductDetail({ ...currentObj, childProductDetail: currentObj.childGtin, isDefault: true })\n ]\n }\n return [...acc, newProduct]\n }\n }, [])\n\n //// 2. Update all Grouped Product data and Product Details Data\n for (let i = 0; i < massagedPatch.length; i++) {\n const patch: Product = massagedPatch[i]\n const result = await createProduct(patch, context)\n results.push({ ...result, cuFlag: '+' })\n }\n\n return results\n } catch (error) {\n throw error\n }\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Product])\n async updateMultipleProduct(\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Product[]> {\n try {\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const patch: NewProduct = _createRecords[i]\n const result = await createProduct(patch, context)\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const patch: ProductPatch = _updateRecords[i]\n const result = await updateProduct(patch.id, patch, context)\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n } catch (error) {\n throw error\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async linkProduct(\n @Arg('productSetId') productSetId: string,\n @Arg('patches', type => [ProductPatch]) patches: ProductPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { tx } = context.state\n\n let productSet = await tx.getRepository(ProductSet).findOne({\n where: { id: productSetId },\n relations: ['domain', 'creator', 'updater', 'product']\n })\n\n let existingProductLink: any = productSet.product\n\n let newProductLink: Product[] = patches.reduce((acc, curr) => {\n if (!existingProductLink.find(itm => itm.id == curr.id)) {\n acc.push({ id: curr.id })\n }\n return acc\n }, [])\n\n let removeProductLink: Product[] = existingProductLink.reduce((acc, curr) => {\n if (!patches.find(itm => itm.id == curr.id)) {\n acc.push({ id: curr.id })\n }\n return acc\n }, [])\n\n if (newProductLink.length > 0) {\n for (let i = 0; i < newProductLink.length; i++) {\n const patch: Product = { ...newProductLink[i], productSet }\n await updateProduct(newProductLink[i].id, patch, context)\n }\n }\n\n if (removeProductLink.length > 0) {\n for (let i = 0; i < removeProductLink.length; i++) {\n const patch: Product = { ...removeProductLink[i], productSet: null }\n await updateProduct(removeProductLink[i].id, patch, context)\n }\n }\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteProduct(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx, user, domain } = context.state\n const productSetRepo: Repository<Product> = tx.getRepository(Product)\n const productSet = await productSetRepo.findOneBy({ domain: { id: domain.id }, id })\n\n await productSetRepo.save({\n ...productSet,\n status: PRODUCT_STATUS.DELETED,\n updater: user\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteProducts(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx, user } = context.state\n const productRepo = tx.getRepository(Product)\n\n await productRepo.update(\n {\n id: In(ids)\n },\n {\n deletedAt: new Date()\n }\n )\n\n return true\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"mutation\") ')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async undeleteProducts(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { tx, user } = context.state\n const productRepo = tx.getRepository(Product)\n\n await productRepo.update(\n {\n id: In(ids)\n },\n {\n deletedAt: null\n }\n )\n\n return true\n }\n}\n\nexport async function createProduct(product: any, context: ResolverContext) {\n try {\n const { domain, user, tx } = context.state\n\n const productRepo: Repository<Product> = tx.getRepository(Product) || getRepository(Product)\n const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace) || getRepository(Bizplace)\n\n let bizplace: Bizplace\n if (product.bizplace?.id) {\n bizplace = await bizplaceRepo.findOneBy({ id: product.bizplace.id })\n } else if (context.state?.bizplace) {\n bizplace = context.state.bizplace\n } else {\n bizplace = await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n }\n\n if (product?.productRef?.id) {\n product.productRef = await productRepo.findOneBy({ id: product.productRef.id })\n }\n\n if (!product?.id) delete product.id\n\n await validateProduct(\n {\n ...product,\n bizplace,\n domain\n },\n context\n )\n\n if (product.uom) {\n product.primaryUnit = product.uom\n }\n\n if (product.uomValue) {\n product.primaryValue = product.uomValue\n }\n\n const result = await productRepo.save({\n ...product,\n bizplace,\n domain,\n creator: user,\n updater: user\n })\n\n let productDetails = product.productDetails\n if (!productDetails) {\n productDetails = [new ProductDetail({ ...product, product: result, isDefault: true })]\n if (productDetails[0].gtin == null || productDetails[0] == undefined) {\n productDetails[0].gtin = product.sku\n }\n }\n\n await updateMultipleProductDetail(result.id, productDetails, context)\n\n if (product.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: product.thumbnail,\n refType: Product.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n } catch (error) {\n throw error\n }\n}\n\nexport async function createProducts(products, context: ResolverContext) {\n const { resolve, reject } = await promisesAll.all(products.map(product => createProduct(product, context)))\n\n if (reject.length) {\n reject.forEach(({ name, message }) => logger.error(`${name}: ${message}`))\n\n return reject\n }\n\n return resolve\n}\n\nexport async function updateProduct(id: string, patch, context) {\n try {\n const { user, tx, domain } = context.state\n\n const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace)\n const productRepo: Repository<Product> = tx.getRepository(Product)\n const productDetailRepo: Repository<ProductDetail> = tx.getRepository(ProductDetail)\n\n let product = await productRepo.findOne({ where: { id }, relations: ['domain'] })\n\n let productDetail = await productDetailRepo.findOne({\n where: { product: { id }, isDefault: true },\n relations: ['domain']\n })\n\n if (patch.productRef && patch.productRef.id) {\n patch.productRef = await productRepo.findOne(patch.productRef.id)\n }\n\n let bizplace: Bizplace\n if (product.bizplace?.id) {\n bizplace = await bizplaceRepo.findOneBy({ id: product.bizplace.id })\n } else {\n bizplace = await bizplaceRepo.findOne({ where: { name: domain.name } })\n }\n\n await validateProduct(\n {\n ...product,\n ...patch,\n bizplace,\n domain\n },\n context\n )\n\n if (patch.uom) {\n product.primaryUnit = patch.uom\n }\n\n if (patch.uomValue) {\n product.primaryValue = patch.uomValue\n }\n\n product = await productRepo.save({\n ...product,\n ...patch,\n domain,\n updater: user\n })\n\n if (productDetail) {\n if (product.gtin) {\n delete product.gtin\n }\n productDetail = await updateProductDetail(\n productDetail.id,\n new ProductDetail({ ...product, ...patch, product }),\n context\n )\n } else {\n productDetail = await createProductDetail(\n new ProductDetail({ ...product, ...patch, product, isDefault: true }),\n context\n )\n }\n\n const productId = id\n if (patch.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [productId] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.thumbnail,\n refType: Product.name,\n refBy: product.id\n }\n },\n context\n )\n }\n\n return product\n } catch (error) {\n throw error\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Bizplace } from '@things-factory/biz-base';
|
|
3
|
+
import { Domain, ListParam } from '@things-factory/shell';
|
|
4
|
+
import { Product } from './product';
|
|
5
|
+
import { ProductList } from './product-types';
|
|
6
|
+
export declare class ProductQuery {
|
|
7
|
+
product(sku: string, context: ResolverContext): Promise<Product>;
|
|
8
|
+
productById(id: string, context: ResolverContext): Promise<Product>;
|
|
9
|
+
products(params: ListParam, context: ResolverContext): Promise<ProductList>;
|
|
10
|
+
myBizplaceProducts(params: ListParam, context: ResolverContext): Promise<ProductList>;
|
|
11
|
+
productsByBizplace(params: ListParam, context: ResolverContext): Promise<ProductList>;
|
|
12
|
+
/**
|
|
13
|
+
* @description this resolver was specially made to return huge products data
|
|
14
|
+
* without dropping off performance due to typegraphql limitations
|
|
15
|
+
* @returns pure product data only. there will be no other table joined to avoid
|
|
16
|
+
* ORM lagging issue (converting to object extremely withdraws the performance)
|
|
17
|
+
* */
|
|
18
|
+
pureProductsByBizplace(params: ListParam, context: ResolverContext): Promise<ProductList>;
|
|
19
|
+
domain(product: Product): Promise<Domain>;
|
|
20
|
+
bizplace(product: Product): Promise<Bizplace>;
|
|
21
|
+
creator(product: Product): Promise<User>;
|
|
22
|
+
updater(product: Product): Promise<User>;
|
|
23
|
+
parentProductRef(product: Product): Promise<Product>;
|
|
24
|
+
productRef(product: Product): Promise<Product>;
|
|
25
|
+
thumbnail(product: Product): Promise<string | undefined>;
|
|
26
|
+
productInformation(product: Product): String;
|
|
27
|
+
warehouseId(product: Product): Promise<String | undefined>;
|
|
28
|
+
}
|
|
@@ -222,6 +222,7 @@ let ProductQuery = class ProductQuery {
|
|
|
222
222
|
return items[0].warehouseId || null;
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
|
+
exports.ProductQuery = ProductQuery;
|
|
225
226
|
tslib_1.__decorate([
|
|
226
227
|
(0, type_graphql_1.Directive)('@privilege(category: "order", privilege: "query", domainOwnerGranted: true)'),
|
|
227
228
|
(0, type_graphql_1.Query)(returns => product_1.Product),
|
|
@@ -339,10 +340,9 @@ tslib_1.__decorate([
|
|
|
339
340
|
tslib_1.__metadata("design:paramtypes", [product_1.Product]),
|
|
340
341
|
tslib_1.__metadata("design:returntype", Promise)
|
|
341
342
|
], ProductQuery.prototype, "warehouseId", null);
|
|
342
|
-
ProductQuery = tslib_1.__decorate([
|
|
343
|
+
exports.ProductQuery = ProductQuery = tslib_1.__decorate([
|
|
343
344
|
(0, type_graphql_1.Resolver)(product_1.Product)
|
|
344
345
|
], ProductQuery);
|
|
345
|
-
exports.ProductQuery = ProductQuery;
|
|
346
346
|
function buildCustomConditions(params, context, bizplaces) {
|
|
347
347
|
const deletedFilter = params.filters.find(x => x.name == 'deleted');
|
|
348
348
|
const productFilters = params.filters.find(x => x.name == 'product_info');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-query.js","sourceRoot":"","sources":["../../../server/service/product/product-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAC9F,qCAA0D;AAE1D,qEAA4D;AAC5D,yDAAgD;AAChD,uDAAmK;AACnK,6CAA4C;AAC5C,iDAAuH;AAEvH,qEAAgE;AAChE,uCAAmC;AACnC,mDAA6C;AAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,qCAAqC,CAAC,CAAA;AAG9D,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGjB,AAAN,KAAK,CAAC,OAAO,CAAa,GAAW,EAAS,OAAwB;QACpE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhD,IAAI,QAAQ,EAAE;YACZ,OAAO,MAAM,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,OAAO,CAAC;gBAC1C,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;oBACzB,GAAG;oBACH,QAAQ,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE;iBAC9B;gBACD,SAAS,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC;aACtE,CAAC,CAAA;SACH;aAAM;YACL,OAAO,MAAM,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,OAAO,CAAC;gBAC1C,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;oBACzB,GAAG;oBACH,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAA,YAAE,EAAC,MAAM,IAAA,kCAAuB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE;iBAClE;gBACD,SAAS,EAAE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AAA;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,0BAA0B;QAC1B,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;KAC5C;IAED,MAAM,EAAE,GAAG,IAAA,qCAA6B,EAAC;QACvC,UAAU,EAAE,IAAA,qBAAa,EAAC,iBAAO,CAAC;QAClC,KAAK,EAAE,SAAS;QAChB,MAAM;QACN,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC;KAC5C,CAAC,CAAA;IAEF,IAAI,cAAc,EAAE;QAClB,EAAE,CAAC,QAAQ,CACT,IAAI,kBAAQ,CAAC,GAAG,CAAC,EAAE;YACjB,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACpC,MAAM,SAAS,GAAG,IAAA,sBAAc,EAC9B,EAAE,CAAC,KAAK,EACR,MAAM,EACN,cAAc,CAAC,QAAQ,EACvB,cAAc,CAAC,KAAK,EACpB,cAAc,CAAC,QAAQ,EACvB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,MAAM,CACvC,CAAA;gBAED,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,CAAA;YACrD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CACH,CAAA;KACF;IAED,OAAO,EAAE,CAAA;AACX,CAAC","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\nimport { Brackets, In, SelectQueryBuilder } from 'typeorm'\n\nimport { Attachment } from '@things-factory/attachment-base'\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace, getCompaniesBizplaces, getCompanyBizplace, getMyBizplace, getPartnersCompanyBizplaces, getPermittedBizplaceIds } from '@things-factory/biz-base'\nimport { logger } from '@things-factory/env'\nimport { buildCondition, Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ProductDetail } from '../product-detail/product-detail'\nimport { Product } from './product'\nimport { ProductList } from './product-types'\n\nconst debug = require('debug')('things-factory:product-base:product')\n\n@Resolver(Product)\nexport class ProductQuery {\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Product)\n async product(@Arg('sku') sku: string, @Ctx() context: ResolverContext): Promise<Product> {\n const { domain, user, bizplace } = context.state\n\n if (bizplace) {\n return await getRepository(Product).findOne({\n where: {\n domain: { id: domain.id },\n sku,\n bizplace: { id: bizplace.id }\n },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n } else {\n return await getRepository(Product).findOne({\n where: {\n domain: { id: domain.id },\n sku,\n bizplace: { id: In(await getPermittedBizplaceIds(domain, user)) }\n },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Product)\n async productById(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Product> {\n const { domain, user } = context.state\n return await getRepository(Product).findOne({\n where: { domain: { id: domain.id }, id },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async products(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const { domains }: { domains: Domain[] } = user as any /* TODO clarify this */\n let bizplaces: Bizplace[]\n\n if (!params.filters.find((filter: any) => filter.name === 'bizplace_id')) {\n const warehouseDomain: Domain = domain\n const companiesBizplaces: Bizplace[] = await getCompaniesBizplaces(domains, warehouseDomain)\n const partnersCompanyBizplaces: Bizplace[] = await getPartnersCompanyBizplaces(domain, user)\n\n bizplaces = [...companiesBizplaces, ...partnersCompanyBizplaces]\n } else {\n const bizplaceId: string[] = params.filters.filter(param => param.name == 'bizplace_id').map(item => item.value)\n\n const foundBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceId[0] },\n relations: ['company', 'company.domain']\n })\n\n if (foundBizplace) {\n const companyDomain: Domain = foundBizplace.company?.domain\n const companyBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { domain: { id: companyDomain.id } }\n })\n\n bizplaces = [companyBizplace, foundBizplace]\n }\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb\n .leftJoinAndSelect('Product.productDetails', 'ProductDetails')\n .leftJoinAndSelect('ProductDetails.childProductDetail', 'ChildProductDetail')\n .getManyAndCount()\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async myBizplaceProducts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n try {\n const { domain, user }: { domain: Domain; user: User } = context.state\n const bizplaceFilter = params.filters.find(filter => filter.name === 'bizplace_id')\n\n let bizplaces: Bizplace[] = []\n if (!bizplaceFilter) {\n bizplaces.push(await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } }))\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb.leftJoinAndSelect('Product.productDetails', 'ProductDetails').leftJoinAndSelect('Product.routing', 'Routing').getManyAndCount()\n\n items = items.map(itm => {\n let defaultProductDetail = itm.productDetails.find(itm => itm.isDefault)\n return {\n ...itm,\n ...new ProductDetail(defaultProductDetail, true)\n }\n })\n\n return { items, total }\n } catch (error) {\n logger.error(`product-query[myBizplaceProducts]: ${error}`)\n throw error\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async productsByBizplace(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const bizplaceFilter = params.filters.find(x => x.name == 'bizplace')\n\n try {\n let bizplaces: Bizplace[]\n if (!bizplaceFilter || bizplaceFilter.value == '') {\n bizplaces = [await getMyBizplace(domain, user), await getCompanyBizplace(domain, user)]\n } else {\n let myBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceFilter.value },\n relations: ['company', 'company.domain']\n })\n\n bizplaces = [\n myBizplace,\n await getRepository(Bizplace).findOne({\n where: { domain: { id: myBizplace.company.domain.id } }\n })\n ]\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb.leftJoinAndSelect('Product.productDetails', 'ProductDetails').getManyAndCount()\n\n items = items.map(itm => {\n let defaultProductDetail = itm.productDetails?.find(itm => itm.isDefault)\n return {\n ...itm,\n ...new ProductDetail(defaultProductDetail, true)\n }\n })\n\n return { items, total }\n } catch (error) {\n throw error\n }\n }\n\n /**\n * @description this resolver was specially made to return huge products data\n * without dropping off performance due to typegraphql limitations\n * @returns pure product data only. there will be no other table joined to avoid\n * ORM lagging issue (converting to object extremely withdraws the performance)\n * */\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async pureProductsByBizplace(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const bizplaceFilter = params.filters.find(x => x.name == 'bizplace')\n\n try {\n let bizplaces: Bizplace[]\n if (!bizplaceFilter || bizplaceFilter.value == '') {\n bizplaces = [await getMyBizplace(domain, user), await getCompanyBizplace(domain, user)]\n } else {\n let myBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceFilter.value },\n relations: ['company', 'company.domain']\n })\n\n bizplaces = [\n myBizplace,\n await getRepository(Bizplace).findOne({\n where: { domain: { id: myBizplace.company.domain.id } }\n })\n ]\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n let items = await (await qb.getRawMany()).map(item => new Product(item))\n let total = await qb.getCount()\n\n return { items, total }\n } catch (error) {\n throw error\n }\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() product: Product): Promise<Domain> {\n if (product.domainId) return await getRepository(Domain).findOneBy({ id: product.domainId })\n else return null\n }\n\n @FieldResolver(type => Bizplace)\n async bizplace(@Root() product: Product): Promise<Bizplace> {\n if (product.bizplaceId) return await getRepository(Bizplace).findOneBy({ id: product.bizplaceId })\n else return null\n }\n\n @FieldResolver(type => User)\n async creator(@Root() product: Product): Promise<User> {\n if (product.creatorId) return await getRepository(User).findOneBy({ id: product.creatorId })\n else return null\n }\n\n @FieldResolver(type => User)\n async updater(@Root() product: Product): Promise<User> {\n if (product.updaterId) return await getRepository(User).findOneBy({ id: product.updaterId })\n else return null\n }\n\n @FieldResolver(type => Product)\n async parentProductRef(@Root() product: Product): Promise<Product> {\n if (product.parentProductRefId) return await getRepository(Product).findOneBy({ id: product.parentProductRefId })\n else return null\n }\n\n @FieldResolver(type => Product)\n async productRef(@Root() product: Product): Promise<Product> {\n if (product.productRefId) return await getRepository(Product).findOneBy({ id: product.productRefId })\n else return null\n }\n\n @FieldResolver(type => String)\n async thumbnail(@Root() product: Product): Promise<string | undefined> {\n const attachment: Attachment = await getRepository(Attachment).findOne({\n where: {\n domain: { id: product.domainId },\n refBy: product.id\n }\n })\n\n return attachment?.fullpath\n }\n\n @FieldResolver(type => String)\n productInformation(@Root() product: Product): String {\n return `[${product.sku}] ${product.name}${product.description ? ` - ${product.description}` : ''}`\n }\n\n @FieldResolver(type => String, { nullable: true })\n async warehouseId(@Root() product: Product): Promise<String | undefined> {\n if (!product.warehouseName) return null\n\n const items = await getRepository(Product).query(`\n SELECT w.id as \"warehouseId\" FROM products p LEFT JOIN warehouses w ON p.warehouse_name = w.name and w.domain_id = p.domain_id WHERE p.id = '${product.id}'\n `)\n\n return items[0].warehouseId || null\n }\n}\n\nfunction buildCustomConditions(params, context, bizplaces): SelectQueryBuilder<Product> {\n const deletedFilter = params.filters.find(x => x.name == 'deleted')\n const productFilters = params.filters.find(x => x.name == 'product_info')\n const productFilterColumns = ['sku', 'brandSku', 'name', 'description', 'brand', 'subBrand']\n\n try {\n params.filters = [\n ...params.filters.filter(x => ['product_info', 'bizplace', 'bizplaceId', 'deleted'].indexOf(x.name) == -1),\n { name: 'deletedAt', operator: deletedFilter?.value ? 'is_not_null' : 'is_null' },\n { name: 'bizplaceId', operator: 'in', value: bizplaces.map(bizplace => bizplace.id) }\n ]\n } catch (err) {\n // error with no bizplace.\n debug('[WARN] params.filters', err.message)\n }\n\n const qb = getQueryBuilderFromListParams({\n repository: getRepository(Product),\n alias: 'Product',\n params,\n domain: context.domain,\n searchables: ['sku', 'name', 'description']\n })\n\n if (productFilters) {\n qb.andWhere(\n new Brackets(qb2 => {\n productFilterColumns.forEach(filter => {\n const condition = buildCondition(\n qb.alias,\n filter,\n productFilters.operator,\n productFilters.value,\n productFilters.relation,\n Object.keys(qb.getParameters()).length\n )\n\n qb2.orWhere(condition.clause, condition.parameters)\n })\n })\n )\n }\n\n return qb\n}\n"]}
|
|
1
|
+
{"version":3,"file":"product-query.js","sourceRoot":"","sources":["../../../server/service/product/product-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAC9F,qCAA0D;AAE1D,qEAA4D;AAC5D,yDAAgD;AAChD,uDAAmK;AACnK,6CAA4C;AAC5C,iDAAuH;AAEvH,qEAAgE;AAChE,uCAAmC;AACnC,mDAA6C;AAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,qCAAqC,CAAC,CAAA;AAG9D,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGjB,AAAN,KAAK,CAAC,OAAO,CAAa,GAAW,EAAS,OAAwB;QACpE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,MAAM,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,OAAO,CAAC;gBAC1C,KAAK,EA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;YACjB,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACpC,MAAM,SAAS,GAAG,IAAA,sBAAc,EAC9B,EAAE,CAAC,KAAK,EACR,MAAM,EACN,cAAc,CAAC,QAAQ,EACvB,cAAc,CAAC,KAAK,EACpB,cAAc,CAAC,QAAQ,EACvB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,MAAM,CACvC,CAAA;gBAED,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,CAAA;YACrD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\nimport { Brackets, In, SelectQueryBuilder } from 'typeorm'\n\nimport { Attachment } from '@things-factory/attachment-base'\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace, getCompaniesBizplaces, getCompanyBizplace, getMyBizplace, getPartnersCompanyBizplaces, getPermittedBizplaceIds } from '@things-factory/biz-base'\nimport { logger } from '@things-factory/env'\nimport { buildCondition, Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ProductDetail } from '../product-detail/product-detail'\nimport { Product } from './product'\nimport { ProductList } from './product-types'\n\nconst debug = require('debug')('things-factory:product-base:product')\n\n@Resolver(Product)\nexport class ProductQuery {\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Product)\n async product(@Arg('sku') sku: string, @Ctx() context: ResolverContext): Promise<Product> {\n const { domain, user, bizplace } = context.state\n\n if (bizplace) {\n return await getRepository(Product).findOne({\n where: {\n domain: { id: domain.id },\n sku,\n bizplace: { id: bizplace.id }\n },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n } else {\n return await getRepository(Product).findOne({\n where: {\n domain: { id: domain.id },\n sku,\n bizplace: { id: In(await getPermittedBizplaceIds(domain, user)) }\n },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Product)\n async productById(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Product> {\n const { domain, user } = context.state\n return await getRepository(Product).findOne({\n where: { domain: { id: domain.id }, id },\n relations: ['domain', 'bizplace', 'productRef', 'creator', 'updater']\n })\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async products(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const { domains }: { domains: Domain[] } = user as any /* TODO clarify this */\n let bizplaces: Bizplace[]\n\n if (!params.filters.find((filter: any) => filter.name === 'bizplace_id')) {\n const warehouseDomain: Domain = domain\n const companiesBizplaces: Bizplace[] = await getCompaniesBizplaces(domains, warehouseDomain)\n const partnersCompanyBizplaces: Bizplace[] = await getPartnersCompanyBizplaces(domain, user)\n\n bizplaces = [...companiesBizplaces, ...partnersCompanyBizplaces]\n } else {\n const bizplaceId: string[] = params.filters.filter(param => param.name == 'bizplace_id').map(item => item.value)\n\n const foundBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceId[0] },\n relations: ['company', 'company.domain']\n })\n\n if (foundBizplace) {\n const companyDomain: Domain = foundBizplace.company?.domain\n const companyBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { domain: { id: companyDomain.id } }\n })\n\n bizplaces = [companyBizplace, foundBizplace]\n }\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb\n .leftJoinAndSelect('Product.productDetails', 'ProductDetails')\n .leftJoinAndSelect('ProductDetails.childProductDetail', 'ChildProductDetail')\n .getManyAndCount()\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async myBizplaceProducts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n try {\n const { domain, user }: { domain: Domain; user: User } = context.state\n const bizplaceFilter = params.filters.find(filter => filter.name === 'bizplace_id')\n\n let bizplaces: Bizplace[] = []\n if (!bizplaceFilter) {\n bizplaces.push(await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } }))\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb.leftJoinAndSelect('Product.productDetails', 'ProductDetails').leftJoinAndSelect('Product.routing', 'Routing').getManyAndCount()\n\n items = items.map(itm => {\n let defaultProductDetail = itm.productDetails.find(itm => itm.isDefault)\n return {\n ...itm,\n ...new ProductDetail(defaultProductDetail, true)\n }\n })\n\n return { items, total }\n } catch (error) {\n logger.error(`product-query[myBizplaceProducts]: ${error}`)\n throw error\n }\n }\n\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async productsByBizplace(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const bizplaceFilter = params.filters.find(x => x.name == 'bizplace')\n\n try {\n let bizplaces: Bizplace[]\n if (!bizplaceFilter || bizplaceFilter.value == '') {\n bizplaces = [await getMyBizplace(domain, user), await getCompanyBizplace(domain, user)]\n } else {\n let myBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceFilter.value },\n relations: ['company', 'company.domain']\n })\n\n bizplaces = [\n myBizplace,\n await getRepository(Bizplace).findOne({\n where: { domain: { id: myBizplace.company.domain.id } }\n })\n ]\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n\n let [items, total] = await qb.leftJoinAndSelect('Product.productDetails', 'ProductDetails').getManyAndCount()\n\n items = items.map(itm => {\n let defaultProductDetail = itm.productDetails?.find(itm => itm.isDefault)\n return {\n ...itm,\n ...new ProductDetail(defaultProductDetail, true)\n }\n })\n\n return { items, total }\n } catch (error) {\n throw error\n }\n }\n\n /**\n * @description this resolver was specially made to return huge products data\n * without dropping off performance due to typegraphql limitations\n * @returns pure product data only. there will be no other table joined to avoid\n * ORM lagging issue (converting to object extremely withdraws the performance)\n * */\n @Directive('@privilege(category: \"order\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => ProductList)\n async pureProductsByBizplace(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ProductList> {\n const { domain, user } = context.state\n const bizplaceFilter = params.filters.find(x => x.name == 'bizplace')\n\n try {\n let bizplaces: Bizplace[]\n if (!bizplaceFilter || bizplaceFilter.value == '') {\n bizplaces = [await getMyBizplace(domain, user), await getCompanyBizplace(domain, user)]\n } else {\n let myBizplace: Bizplace = await getRepository(Bizplace).findOne({\n where: { id: bizplaceFilter.value },\n relations: ['company', 'company.domain']\n })\n\n bizplaces = [\n myBizplace,\n await getRepository(Bizplace).findOne({\n where: { domain: { id: myBizplace.company.domain.id } }\n })\n ]\n }\n\n const qb: SelectQueryBuilder<Product> = buildCustomConditions(params, context, bizplaces)\n let items = await (await qb.getRawMany()).map(item => new Product(item))\n let total = await qb.getCount()\n\n return { items, total }\n } catch (error) {\n throw error\n }\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() product: Product): Promise<Domain> {\n if (product.domainId) return await getRepository(Domain).findOneBy({ id: product.domainId })\n else return null\n }\n\n @FieldResolver(type => Bizplace)\n async bizplace(@Root() product: Product): Promise<Bizplace> {\n if (product.bizplaceId) return await getRepository(Bizplace).findOneBy({ id: product.bizplaceId })\n else return null\n }\n\n @FieldResolver(type => User)\n async creator(@Root() product: Product): Promise<User> {\n if (product.creatorId) return await getRepository(User).findOneBy({ id: product.creatorId })\n else return null\n }\n\n @FieldResolver(type => User)\n async updater(@Root() product: Product): Promise<User> {\n if (product.updaterId) return await getRepository(User).findOneBy({ id: product.updaterId })\n else return null\n }\n\n @FieldResolver(type => Product)\n async parentProductRef(@Root() product: Product): Promise<Product> {\n if (product.parentProductRefId) return await getRepository(Product).findOneBy({ id: product.parentProductRefId })\n else return null\n }\n\n @FieldResolver(type => Product)\n async productRef(@Root() product: Product): Promise<Product> {\n if (product.productRefId) return await getRepository(Product).findOneBy({ id: product.productRefId })\n else return null\n }\n\n @FieldResolver(type => String)\n async thumbnail(@Root() product: Product): Promise<string | undefined> {\n const attachment: Attachment = await getRepository(Attachment).findOne({\n where: {\n domain: { id: product.domainId },\n refBy: product.id\n }\n })\n\n return attachment?.fullpath\n }\n\n @FieldResolver(type => String)\n productInformation(@Root() product: Product): String {\n return `[${product.sku}] ${product.name}${product.description ? ` - ${product.description}` : ''}`\n }\n\n @FieldResolver(type => String, { nullable: true })\n async warehouseId(@Root() product: Product): Promise<String | undefined> {\n if (!product.warehouseName) return null\n\n const items = await getRepository(Product).query(`\n SELECT w.id as \"warehouseId\" FROM products p LEFT JOIN warehouses w ON p.warehouse_name = w.name and w.domain_id = p.domain_id WHERE p.id = '${product.id}'\n `)\n\n return items[0].warehouseId || null\n }\n}\n\nfunction buildCustomConditions(params, context, bizplaces): SelectQueryBuilder<Product> {\n const deletedFilter = params.filters.find(x => x.name == 'deleted')\n const productFilters = params.filters.find(x => x.name == 'product_info')\n const productFilterColumns = ['sku', 'brandSku', 'name', 'description', 'brand', 'subBrand']\n\n try {\n params.filters = [\n ...params.filters.filter(x => ['product_info', 'bizplace', 'bizplaceId', 'deleted'].indexOf(x.name) == -1),\n { name: 'deletedAt', operator: deletedFilter?.value ? 'is_not_null' : 'is_null' },\n { name: 'bizplaceId', operator: 'in', value: bizplaces.map(bizplace => bizplace.id) }\n ]\n } catch (err) {\n // error with no bizplace.\n debug('[WARN] params.filters', err.message)\n }\n\n const qb = getQueryBuilderFromListParams({\n repository: getRepository(Product),\n alias: 'Product',\n params,\n domain: context.domain,\n searchables: ['sku', 'name', 'description']\n })\n\n if (productFilters) {\n qb.andWhere(\n new Brackets(qb2 => {\n productFilterColumns.forEach(filter => {\n const condition = buildCondition(\n qb.alias,\n filter,\n productFilters.operator,\n productFilters.value,\n productFilters.relation,\n Object.keys(qb.getParameters()).length\n )\n\n qb2.orWhere(condition.clause, condition.parameters)\n })\n })\n )\n }\n\n return qb\n}\n"]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js';
|
|
2
|
+
import { BizplacePatch } from '@things-factory/biz-base';
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell';
|
|
4
|
+
import { ProductDetailPatch } from '../product-detail/product-detail-types';
|
|
5
|
+
import { Product } from './product';
|
|
6
|
+
export declare class NewProduct {
|
|
7
|
+
id?: string;
|
|
8
|
+
sku?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
bizplace?: BizplacePatch;
|
|
11
|
+
description?: string;
|
|
12
|
+
productRef?: ObjectRef;
|
|
13
|
+
parentProductRef?: ObjectRef;
|
|
14
|
+
childProducts?: ObjectRef[];
|
|
15
|
+
productDetails?: ProductDetailPatch[];
|
|
16
|
+
bundleQty?: number;
|
|
17
|
+
type?: string;
|
|
18
|
+
expirationPeriod?: number;
|
|
19
|
+
movement?: string;
|
|
20
|
+
weightUnit?: string;
|
|
21
|
+
nettWeight?: number;
|
|
22
|
+
density?: number;
|
|
23
|
+
packingType?: string;
|
|
24
|
+
lengthUnit?: string;
|
|
25
|
+
costPrice?: number;
|
|
26
|
+
afterTaxCostPrice?: number;
|
|
27
|
+
sellPrice?: number;
|
|
28
|
+
afterTaxSalesPrice?: number;
|
|
29
|
+
mrpPrice?: number;
|
|
30
|
+
bufferQty?: number;
|
|
31
|
+
minQty?: number;
|
|
32
|
+
maxQty?: number;
|
|
33
|
+
width?: number;
|
|
34
|
+
depth?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
primaryUnit?: string;
|
|
37
|
+
primaryValue?: number;
|
|
38
|
+
uom?: string;
|
|
39
|
+
uomValue?: number;
|
|
40
|
+
inventoryAccountCode?: string;
|
|
41
|
+
cogsAccountCode?: string;
|
|
42
|
+
auxUnit1?: string;
|
|
43
|
+
auxValue1?: string;
|
|
44
|
+
auxUnit2?: string;
|
|
45
|
+
auxValue2?: string;
|
|
46
|
+
auxUnit3?: string;
|
|
47
|
+
auxValue3?: string;
|
|
48
|
+
auxUnit4?: string;
|
|
49
|
+
auxValue4?: string;
|
|
50
|
+
auxUnit5?: string;
|
|
51
|
+
auxValue5?: string;
|
|
52
|
+
groupType?: string;
|
|
53
|
+
brandSku?: string;
|
|
54
|
+
brand?: string;
|
|
55
|
+
subBrand?: string;
|
|
56
|
+
isRequiredCheckExpiry?: boolean;
|
|
57
|
+
isRequireSerialNumberScanning?: boolean;
|
|
58
|
+
isRequireSerialNumberScanningInbound?: boolean;
|
|
59
|
+
isRequireSerialNumberScanningOutbound?: boolean;
|
|
60
|
+
gtin?: string;
|
|
61
|
+
grossWeight?: number;
|
|
62
|
+
volume?: number;
|
|
63
|
+
volumeSize?: number;
|
|
64
|
+
routing?: ObjectRef;
|
|
65
|
+
warehouseName?: string;
|
|
66
|
+
thumbnail?: FileUpload;
|
|
67
|
+
pickingStrategy?: string;
|
|
68
|
+
inboundUnit?: string;
|
|
69
|
+
convertWeight?: number;
|
|
70
|
+
boxInQty?: number;
|
|
71
|
+
category?: string;
|
|
72
|
+
isAuction?: boolean;
|
|
73
|
+
releaseType?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare class ProductList {
|
|
76
|
+
items?: Product[];
|
|
77
|
+
total?: number;
|
|
78
|
+
}
|
|
79
|
+
export declare class ProductPatch {
|
|
80
|
+
id?: string;
|
|
81
|
+
sku?: string;
|
|
82
|
+
name?: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
bizplace?: ObjectRef;
|
|
85
|
+
productRef?: ObjectRef;
|
|
86
|
+
parentProductRef?: ObjectRef;
|
|
87
|
+
childProducts?: ObjectRef[];
|
|
88
|
+
bundleQty?: number;
|
|
89
|
+
refCode?: string;
|
|
90
|
+
packingType?: string;
|
|
91
|
+
packingSize?: number;
|
|
92
|
+
type?: string;
|
|
93
|
+
expirationPeriod?: number;
|
|
94
|
+
movement?: string;
|
|
95
|
+
weightUnit?: string;
|
|
96
|
+
nettWeight?: number;
|
|
97
|
+
density?: number;
|
|
98
|
+
lengthUnit?: string;
|
|
99
|
+
costPrice?: number;
|
|
100
|
+
afterTaxCostPrice: number;
|
|
101
|
+
sellPrice?: number;
|
|
102
|
+
afterTaxSalesPrice?: number;
|
|
103
|
+
mrpPrice?: number;
|
|
104
|
+
bufferQty?: number;
|
|
105
|
+
minQty?: number;
|
|
106
|
+
maxQty?: number;
|
|
107
|
+
width?: number;
|
|
108
|
+
depth?: number;
|
|
109
|
+
height?: number;
|
|
110
|
+
inventoryAccountCode?: string;
|
|
111
|
+
cogsAccountCode?: string;
|
|
112
|
+
isTrackedAsInventory: boolean;
|
|
113
|
+
isRequiredCheckExpiry?: boolean;
|
|
114
|
+
isRequireSerialNumberScanning?: boolean;
|
|
115
|
+
isRequireSerialNumberScanningInbound?: boolean;
|
|
116
|
+
isRequireSerialNumberScanningOutbound?: boolean;
|
|
117
|
+
primaryUnit?: string;
|
|
118
|
+
primaryValue?: number;
|
|
119
|
+
uom?: string;
|
|
120
|
+
uomValue?: number;
|
|
121
|
+
auxUnit1?: string;
|
|
122
|
+
auxValue1?: string;
|
|
123
|
+
auxUnit2?: string;
|
|
124
|
+
auxValue2?: string;
|
|
125
|
+
auxUnit3?: string;
|
|
126
|
+
auxValue3?: string;
|
|
127
|
+
auxUnit4?: string;
|
|
128
|
+
auxValue4?: string;
|
|
129
|
+
auxUnit5?: string;
|
|
130
|
+
auxValue5?: string;
|
|
131
|
+
brandSku?: string;
|
|
132
|
+
brand?: string;
|
|
133
|
+
subBrand?: string;
|
|
134
|
+
gtin?: string;
|
|
135
|
+
grossWeight?: number;
|
|
136
|
+
volume?: number;
|
|
137
|
+
volumeSize?: number;
|
|
138
|
+
childGtin?: string;
|
|
139
|
+
childQty?: number;
|
|
140
|
+
routing?: ObjectRef;
|
|
141
|
+
warehouseName?: string;
|
|
142
|
+
thumbnail?: FileUpload;
|
|
143
|
+
pickingStrategy?: string;
|
|
144
|
+
inboundUnit?: string;
|
|
145
|
+
convertWeight?: number;
|
|
146
|
+
boxInQty?: number;
|
|
147
|
+
category?: string;
|
|
148
|
+
isAuction?: boolean;
|
|
149
|
+
releaseType?: string;
|
|
150
|
+
cuFlag?: string;
|
|
151
|
+
}
|