@things-factory/product-base 7.0.0-alpha.0 → 7.0.0-alpha.18
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-product.js","sourceRoot":"","sources":["../../../server/service/product/validate-product.ts"],"names":[],"mappings":";;;;AAAA,4DAAsB;AACtB,qCAAoD;AAKpD,uCAAmC;AAE5B,KAAK,UAAU,eAAe,CAAC,OAAgB,EAAE,OAAwB;IAC9E,MAAM,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"validate-product.js","sourceRoot":"","sources":["../../../server/service/product/validate-product.ts"],"names":[],"mappings":";;;;AAAA,4DAAsB;AACtB,qCAAoD;AAKpD,uCAAmC;AAE5B,KAAK,UAAU,eAAe,CAAC,OAAgB,EAAE,OAAwB;IAC9E,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAE5B,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,gBAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;KACvC;IACD,IAAI,gBAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;KACxC;IACD,IAAI,gBAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;KACxC;IAED,IACE,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,iBAAO,CAAC,CAAC,KAAK,CAAC;QACrC,KAAK,EAAE;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,QAAQ,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE;YACrC,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE;YACjC,EAAE,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,KAAI,IAAI,CAAC,CAAC,CAAC,IAAA,aAAG,EAAC,IAAA,gBAAM,GAAE,CAAC,CAAC,CAAC,CAAC,IAAA,aAAG,EAAC,OAAO,CAAC,EAAE,CAAC;SAC1D;KACF,CAAC,CAAC,GAAG,CAAC,EACP;QACA,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;KACrC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;KACnC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAjCD,0CAiCC","sourcesContent":["import _ from 'lodash'\nimport { EntityManager, IsNull, Not } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { Product } from './product'\n\nexport async function validateProduct(product: Product, context: ResolverContext) {\n const { tx } = context.state\n\n let errors = []\n\n if (_.isEmpty(product.sku) || '') {\n errors.push('Product SKU is required')\n }\n if (_.isEmpty(product.name) || '') {\n errors.push('Product name is required')\n }\n if (_.isEmpty(product.type) || '') {\n errors.push('Product type is required')\n }\n\n if (\n (await tx.getRepository(Product).count({\n where: {\n sku: product.sku,\n bizplace: { id: product.bizplace.id },\n domain: { id: product.domain.id },\n id: product?.id == null ? Not(IsNull()) : Not(product.id)\n }\n })) > 0\n ) {\n errors.push('Duplicated SKU found.')\n }\n\n if (errors.length > 0) {\n throw new Error(errors.join(', '))\n }\n\n return true\n}\n"]}
|