storemw-core-api 1.0.178 → 1.0.180

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.
Files changed (51) hide show
  1. package/dist/controllers/injection_field/injectionFieldController.js +2 -6
  2. package/dist/controllers/injection_field/injectionFieldController.js.map +1 -1
  3. package/dist/lib/query_builder/queryBuilder.js +8 -6
  4. package/dist/lib/query_builder/queryBuilder.js.map +1 -1
  5. package/dist/services/branch/UserBranchService.js +1 -1
  6. package/dist/services/branch/UserBranchService.js.map +1 -1
  7. package/dist/services/injection_field/unuse/LogisticInjectionFieldService.js +116 -0
  8. package/dist/services/injection_field/unuse/LogisticInjectionFieldService.js.map +1 -0
  9. package/dist/services/injection_field/unuse/RepositoryInjectionFieldService.d.ts +1 -0
  10. package/dist/services/injection_field/unuse/RepositoryInjectionFieldService.js +131 -0
  11. package/dist/services/injection_field/unuse/RepositoryInjectionFieldService.js.map +1 -0
  12. package/dist/utils/schemaUtils.js +3 -2
  13. package/dist/utils/schemaUtils.js.map +1 -1
  14. package/package.json +1 -1
  15. package/prisma/schema.prisma +45 -0
  16. package/dist/models/group/GroupModel.d.ts +0 -227
  17. package/dist/models/group/GroupModel.js +0 -13
  18. package/dist/models/group/GroupModel.js.map +0 -1
  19. package/dist/models/group/GroupOwnerModel.d.ts +0 -216
  20. package/dist/models/group/GroupOwnerModel.js +0 -13
  21. package/dist/models/group/GroupOwnerModel.js.map +0 -1
  22. package/dist/models/user/UserPropModel.d.ts +0 -256
  23. package/dist/models/user/UserPropModel.js +0 -13
  24. package/dist/models/user/UserPropModel.js.map +0 -1
  25. package/dist/route_contracts/access_control/accessControlPoliciesRoutes.d.ts +0 -2
  26. package/dist/route_contracts/access_control/accessControlPoliciesRoutes.js +0 -21
  27. package/dist/route_contracts/access_control/accessControlPoliciesRoutes.js.map +0 -1
  28. package/dist/route_contracts/access_control/accessControlRoleRoutes.d.ts +0 -2
  29. package/dist/route_contracts/access_control/accessControlRoleRoutes.js +0 -48
  30. package/dist/route_contracts/access_control/accessControlRoleRoutes.js.map +0 -1
  31. package/dist/route_contracts/access_control/accessControlRolesRoutes.d.ts +0 -2
  32. package/dist/route_contracts/access_control/accessControlRolesRoutes.js +0 -37
  33. package/dist/route_contracts/access_control/accessControlRolesRoutes.js.map +0 -1
  34. package/dist/route_contracts/access_control/accessControlRoutes.d.ts +0 -2
  35. package/dist/route_contracts/access_control/accessControlRoutes.js +0 -18
  36. package/dist/route_contracts/access_control/accessControlRoutes.js.map +0 -1
  37. package/dist/route_contracts/access_control/accessControlUserRolesRoutes.d.ts +0 -2
  38. package/dist/route_contracts/access_control/accessControlUserRolesRoutes.js +0 -21
  39. package/dist/route_contracts/access_control/accessControlUserRolesRoutes.js.map +0 -1
  40. package/dist/route_contracts/auth/authRoutes.d.ts +0 -2
  41. package/dist/route_contracts/auth/authRoutes.js +0 -23
  42. package/dist/route_contracts/auth/authRoutes.js.map +0 -1
  43. package/dist/route_contracts/index.d.ts +0 -2
  44. package/dist/route_contracts/index.js +0 -39
  45. package/dist/route_contracts/index.js.map +0 -1
  46. package/dist/scripts/migrate.js +0 -42
  47. package/dist/scripts/migrate.js.map +0 -1
  48. package/dist/services/file/ImageCompression.d.ts +0 -9
  49. package/dist/services/file/ImageCompression.js +0 -47
  50. package/dist/services/file/ImageCompression.js.map +0 -1
  51. /package/dist/{scripts/migrate.d.ts → services/injection_field/unuse/LogisticInjectionFieldService.d.ts} +0 -0
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ // import {
3
+ // RepositoryInjectionFieldModel,
4
+ // ModelRepositoryInjectionFieldFields,
5
+ // } from "../../../models";
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ // import { DefaultServiceProps } from "../../../utils";
8
+ // import { convertPayloadByTableSchema, validateModelFieldsWithData } from "../../../utils";
9
+ // type RepositoryInjectionFieldMap = {
10
+ // container: {
11
+ // repository: { repositoryId: any };
12
+ // // repository_item: { repositoryId: any; };
13
+ // },
14
+ // pallet: {
15
+ // repository: { repositoryId: any };
16
+ // // repository_item: { repositoryId: any; };
17
+ // },
18
+ // carton: {
19
+ // repository: { repositoryId: any };
20
+ // // repository_item: { repositoryId: any; };
21
+ // },
22
+ // package: {
23
+ // repository: { repositoryId: any };
24
+ // // repository_item: { repositoryId: any; };
25
+ // },
26
+ // package_item: {
27
+ // repository: { repositoryId: any };
28
+ // // repository_item: { repositoryId: any; };
29
+ // };
30
+ // };
31
+ // type RepositoryInjectionFieldModule = keyof RepositoryInjectionFieldMap;
32
+ // // type RepositoryInjectionFieldRef<M extends RepositoryInjectionFieldModule> = keyof RepositoryInjectionFieldMap[M];
33
+ // export const repositoryModulePrefixMap: Record<RepositoryInjectionFieldModule, string> = {
34
+ // container: "cont",
35
+ // pallet: "pl",
36
+ // carton: "cn",
37
+ // package: "pk",
38
+ // package_item: "pki"
39
+ // };
40
+ // // export const repositoryRefPrefixMap: Record<"repository" | "repository_item", string> = {
41
+ // export const repositoryRefPrefixMap: Record<"repository", string> = {
42
+ // repository: "repo",
43
+ // // repository_item: "repo_item",
44
+ // };
45
+ // export type RepositoryInjectionFieldModuleRef = {
46
+ // [M in RepositoryInjectionFieldModule]: {
47
+ // [R in keyof RepositoryInjectionFieldMap[M]]: {
48
+ // module: M;
49
+ // ref: R;
50
+ // } & RepositoryInjectionFieldMap[M][R];
51
+ // }[keyof RepositoryInjectionFieldMap[M]];
52
+ // }[RepositoryInjectionFieldModule];
53
+ // export type RepositoryInjectionFieldServiceProps = DefaultServiceProps & {};
54
+ // export type RepositoryInjectionFieldRemoveProps = {
55
+ // ids: number[]
56
+ // };
57
+ // export type RepositoryInjectionFieldReplaceProps = {
58
+ // data: RepositoryInjectionFieldModuleRef & {
59
+ // fields: any
60
+ // }
61
+ // }
62
+ // const getReplacePayload = (data: RepositoryInjectionFieldReplaceProps["data"]) => {
63
+ // let { module, ref, repositoryId } = data
64
+ // let payload: Record<string, any> = {};
65
+ // payload = {
66
+ // ...payload,
67
+ // ...{
68
+ // [`${ModelRepositoryInjectionFieldFields.field_module}`]: module,
69
+ // [`${ModelRepositoryInjectionFieldFields.field_ref}`]: ref,
70
+ // }
71
+ // }
72
+ // if ("repositoryId" in data) {
73
+ // payload = { ...payload, ...(data?.repositoryId ? { [`${ModelRepositoryInjectionFieldFields.repository_id}`]: repositoryId } : {}) }
74
+ // }
75
+ // const rest = data.fields
76
+ // // apply dynamic prefix: refPrefix_modulePrefix_fieldKey
77
+ // const refPrefix = repositoryRefPrefixMap[ref as keyof typeof repositoryRefPrefixMap] ?? ref;
78
+ // const modulePrefix = repositoryModulePrefixMap[module as RepositoryInjectionFieldModule] ?? module;
79
+ // for (const [key, value] of Object.entries(rest)) {
80
+ // payload[`${refPrefix}_${modulePrefix}_${key}`] = value;
81
+ // }
82
+ // return payload
83
+ // }
84
+ // export const RepositoryInjectionFieldService = (props: RepositoryInjectionFieldServiceProps) => {
85
+ // const {
86
+ // ...rest
87
+ // } = props
88
+ // const repositoryInjectionFieldModel = RepositoryInjectionFieldModel({ ...rest })
89
+ // const replaceRepositoryInjectionField = async ({ data }: RepositoryInjectionFieldReplaceProps) => {
90
+ // const _data = getReplacePayload(data)
91
+ // if (!_data) {
92
+ // throw new Error(`Invalid create payload: ${JSON.stringify(_data)}`);
93
+ // }
94
+ // const where: Record<string, any> = {
95
+ // [ModelRepositoryInjectionFieldFields.field_module]: data.module,
96
+ // [ModelRepositoryInjectionFieldFields.field_ref]: data.ref,
97
+ // ...(data?.repositoryId ? { [ModelRepositoryInjectionFieldFields.repository_id]: data.repositoryId } : {}),
98
+ // };
99
+ // // Narrow: only include branchId if data.ref === "branch"
100
+ // // if (data.ref === "branch") {
101
+ // // where[ModelRepositoryInjectionFieldFields.branch_id] = (data as Extract<RepositoryInjectionFieldModuleRef, { ref: "branch" }>).branchId;
102
+ // // }
103
+ // let modelFields = await repositoryInjectionFieldModel.getFields()
104
+ // let finalData = convertPayloadByTableSchema(_data, modelFields)
105
+ // // console.log('modelFields', modelFields)
106
+ // // console.log('finalData', finalData)
107
+ // // check the request fields are in the exactly schema
108
+ // const resultInvalidFields = validateModelFieldsWithData(modelFields, finalData)
109
+ // if (resultInvalidFields.length > 0) {
110
+ // throw Error(`Invalid injection fields: ${resultInvalidFields.join(", ")} (Request: ${Object.keys(finalData).join(", ")})`)
111
+ // }
112
+ // // check the record exists
113
+ // let exists = await repositoryInjectionFieldModel.get({ where })
114
+ // let response: any = {}
115
+ // if (exists) { // update existing
116
+ // // remove unwanted to override
117
+ // delete finalData.field_module;
118
+ // delete finalData.field_ref;
119
+ // delete finalData.repository_id;
120
+ // delete finalData.repository_item_id;
121
+ // response = await repositoryInjectionFieldModel.update({ data: finalData, where, disableRollback: true })
122
+ // } else { // create new
123
+ // response = await repositoryInjectionFieldModel.create({ data: finalData })
124
+ // }
125
+ // return response
126
+ // }
127
+ // return {
128
+ // replaceRepositoryInjectionField
129
+ // }
130
+ // }
131
+ //# sourceMappingURL=RepositoryInjectionFieldService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RepositoryInjectionFieldService.js","sourceRoot":"","sources":["../../../../src/services/injection_field/unuse/RepositoryInjectionFieldService.ts"],"names":[],"mappings":";AAAA,WAAW;AACX,qCAAqC;AACrC,2CAA2C;AAC3C,qBAAqB;;AAErB,iDAAiD;AAEjD,sFAAsF;AAEtF,uCAAuC;AACvC,mBAAmB;AACnB,6CAA6C;AAC7C,sDAAsD;AACtD,SAAS;AACT,gBAAgB;AAChB,6CAA6C;AAC7C,sDAAsD;AACtD,SAAS;AACT,gBAAgB;AAChB,6CAA6C;AAC7C,sDAAsD;AACtD,SAAS;AACT,iBAAiB;AACjB,6CAA6C;AAC7C,sDAAsD;AACtD,SAAS;AACT,sBAAsB;AACtB,6CAA6C;AAC7C,sDAAsD;AACtD,SAAS;AACT,KAAK;AAEL,2EAA2E;AAC3E,wHAAwH;AAExH,6FAA6F;AAC7F,yBAAyB;AACzB,oBAAoB;AACpB,oBAAoB;AACpB,qBAAqB;AACrB,0BAA0B;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F;AACzF,YAAY;AAEZ,0BAA0B;AAC1B,QAAQ;AAER,eAAe;AACf,0CAA0C;AAC1C,QAAQ;AAER,IAAI","sourcesContent":["// import {\n// RepositoryInjectionFieldModel,\n// ModelRepositoryInjectionFieldFields,\n// } from \"@/models\";\n\n// import { DefaultServiceProps } from \"@/utils\";\n\n// import { convertPayloadByTableSchema, validateModelFieldsWithData } from \"@/utils\";\n\n// type RepositoryInjectionFieldMap = {\n// container: {\n// repository: { repositoryId: any };\n// // repository_item: { repositoryId: any; };\n// },\n// pallet: {\n// repository: { repositoryId: any };\n// // repository_item: { repositoryId: any; };\n// },\n// carton: {\n// repository: { repositoryId: any };\n// // repository_item: { repositoryId: any; };\n// },\n// package: {\n// repository: { repositoryId: any };\n// // repository_item: { repositoryId: any; };\n// },\n// package_item: {\n// repository: { repositoryId: any };\n// // repository_item: { repositoryId: any; };\n// };\n// };\n\n// type RepositoryInjectionFieldModule = keyof RepositoryInjectionFieldMap;\n// // type RepositoryInjectionFieldRef<M extends RepositoryInjectionFieldModule> = keyof RepositoryInjectionFieldMap[M];\n\n// export const repositoryModulePrefixMap: Record<RepositoryInjectionFieldModule, string> = {\n// container: \"cont\",\n// pallet: \"pl\",\n// carton: \"cn\",\n// package: \"pk\",\n// package_item: \"pki\"\n// };\n\n// // export const repositoryRefPrefixMap: Record<\"repository\" | \"repository_item\", string> = {\n// export const repositoryRefPrefixMap: Record<\"repository\", string> = {\n// repository: \"repo\",\n// // repository_item: \"repo_item\",\n// };\n\n// export type RepositoryInjectionFieldModuleRef = {\n// [M in RepositoryInjectionFieldModule]: {\n// [R in keyof RepositoryInjectionFieldMap[M]]: {\n// module: M;\n// ref: R;\n// } & RepositoryInjectionFieldMap[M][R];\n// }[keyof RepositoryInjectionFieldMap[M]];\n// }[RepositoryInjectionFieldModule];\n\n// export type RepositoryInjectionFieldServiceProps = DefaultServiceProps & {};\n\n// export type RepositoryInjectionFieldRemoveProps = {\n// ids: number[]\n// };\n\n// export type RepositoryInjectionFieldReplaceProps = {\n// data: RepositoryInjectionFieldModuleRef & {\n// fields: any\n// }\n// }\n\n// const getReplacePayload = (data: RepositoryInjectionFieldReplaceProps[\"data\"]) => {\n\n// let { module, ref, repositoryId } = data\n\n// let payload: Record<string, any> = {};\n\n// payload = {\n// ...payload,\n// ...{\n// [`${ModelRepositoryInjectionFieldFields.field_module}`]: module,\n// [`${ModelRepositoryInjectionFieldFields.field_ref}`]: ref,\n// }\n// }\n\n// if (\"repositoryId\" in data) {\n// payload = { ...payload, ...(data?.repositoryId ? { [`${ModelRepositoryInjectionFieldFields.repository_id}`]: repositoryId } : {}) }\n// }\n\n// const rest = data.fields\n\n// // apply dynamic prefix: refPrefix_modulePrefix_fieldKey\n// const refPrefix = repositoryRefPrefixMap[ref as keyof typeof repositoryRefPrefixMap] ?? ref;\n// const modulePrefix = repositoryModulePrefixMap[module as RepositoryInjectionFieldModule] ?? module;\n\n// for (const [key, value] of Object.entries(rest)) {\n// payload[`${refPrefix}_${modulePrefix}_${key}`] = value;\n// }\n\n// return payload\n\n// }\n\n// export const RepositoryInjectionFieldService = (props: RepositoryInjectionFieldServiceProps) => {\n\n// const {\n// ...rest\n// } = props\n\n// const repositoryInjectionFieldModel = RepositoryInjectionFieldModel({ ...rest })\n\n// const replaceRepositoryInjectionField = async ({ data }: RepositoryInjectionFieldReplaceProps) => {\n\n// const _data = getReplacePayload(data)\n\n// if (!_data) {\n// throw new Error(`Invalid create payload: ${JSON.stringify(_data)}`);\n// }\n\n// const where: Record<string, any> = {\n// [ModelRepositoryInjectionFieldFields.field_module]: data.module,\n// [ModelRepositoryInjectionFieldFields.field_ref]: data.ref,\n// ...(data?.repositoryId ? { [ModelRepositoryInjectionFieldFields.repository_id]: data.repositoryId } : {}),\n// };\n\n// // Narrow: only include branchId if data.ref === \"branch\"\n// // if (data.ref === \"branch\") {\n// // where[ModelRepositoryInjectionFieldFields.branch_id] = (data as Extract<RepositoryInjectionFieldModuleRef, { ref: \"branch\" }>).branchId;\n// // }\n\n// let modelFields = await repositoryInjectionFieldModel.getFields()\n\n// let finalData = convertPayloadByTableSchema(_data, modelFields)\n\n// // console.log('modelFields', modelFields)\n// // console.log('finalData', finalData)\n\n\n// // check the request fields are in the exactly schema\n// const resultInvalidFields = validateModelFieldsWithData(modelFields, finalData)\n\n// if (resultInvalidFields.length > 0) {\n// throw Error(`Invalid injection fields: ${resultInvalidFields.join(\", \")} (Request: ${Object.keys(finalData).join(\", \")})`)\n// }\n\n// // check the record exists\n// let exists = await repositoryInjectionFieldModel.get({ where })\n\n// let response: any = {}\n\n// if (exists) { // update existing\n\n// // remove unwanted to override\n// delete finalData.field_module;\n// delete finalData.field_ref;\n// delete finalData.repository_id;\n// delete finalData.repository_item_id;\n\n// response = await repositoryInjectionFieldModel.update({ data: finalData, where, disableRollback: true })\n\n// } else { // create new\n// response = await repositoryInjectionFieldModel.create({ data: finalData })\n// }\n\n// return response\n// }\n\n// return {\n// replaceRepositoryInjectionField\n// }\n\n// }\n\n\n"]}
@@ -16,8 +16,9 @@ const validateWithSchema = (schema, source = "params") => (req, res, next) => {
16
16
  (0, utils_1.sendError)(res, "BAD_REQUEST", `Invalid ${source}`, "", `${JSON.stringify(formattedErrors)}`, utils_1.HTTP_STATUS.BAD_REQUEST);
17
17
  return;
18
18
  }
19
- // overwrite request object with parsed+typed data
20
- req[source] = result.data;
19
+ // overwrite request object with parsed+typed data (only matched the validation key)
20
+ // (req as any)[source] = result.data;
21
+ req[source] = { ...req[source], ...result.data };
21
22
  // if (source === "query") {
22
23
  // req.query = result.data as any;
23
24
  // } else {
@@ -1 +1 @@
1
- {"version":3,"file":"schemaUtils.js","sourceRoot":"","sources":["../../src/utils/schemaUtils.ts"],"names":[],"mappings":";;;AACA,6BAAmC;AACnC,mCAAiD;AACjD,mCAAgD;AAEhD;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAC9B,MAAiB,EACjB,SAAsC,QAAQ,EAChD,EAAE,CAAC,CAAC,GAAY,EAAE,GAAa,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ourcesContent":["import { Request, Response, NextFunction } from \"express\";\nimport { z, ZodSchema } from \"zod\";\nimport { sendError, HTTP_STATUS } from \"@/utils\";\nimport { getFormattedZodErrors } from \"@/utils\";\n\n/**\n * Creates a validation middleware from a given Zod schema.\n * @param schema Zod schema to validate against\n * @param source where to validate from (default: \"params\")\n */\nexport const validateWithSchema = (\n schema: ZodSchema,\n source: \"params\" | \"query\" | \"body\" = \"params\"\n) => (req: Request, res: Response, next: NextFunction): void => {\n\n const result = schema.safeParse(req[source]);\n\n if (!result.success) {\n const formattedErrors = getFormattedZodErrors(result.error);\n\n sendError(\n res,\n \"BAD_REQUEST\",\n `Invalid ${source}`,\n \"\",\n `${JSON.stringify(formattedErrors)}`,\n HTTP_STATUS.BAD_REQUEST\n );\n return;\n }\n\n // overwrite request object with parsed+typed data\n (req as any)[source] = result.data;\n\n // if (source === \"query\") {\n // req.query = result.data as any;\n // } else {\n // req.params = result.data as any;\n // }\n\n next();\n};\n\n/**\n * Middleware to validate multiple schemas in order.\n * @param schemas Array of tuples: [ZodSchema, source]\n */\nexport const validateMultipleSchemas = (\n schemas: [ZodSchema, \"params\" | \"query\" | \"body\"][]\n) => {\n return (req: Request, res: Response, next: NextFunction) => {\n let i = 0;\n\n const runNext = () => {\n if (i >= schemas.length) return next(); // all schemas validated\n\n const [schema, source] = schemas[i];\n i++;\n\n validateWithSchema(schema, source)(req, res, (err) => {\n if (err) return; // already handled by validateWithSchema\n runNext(); // validate next schema\n });\n };\n\n runNext();\n };\n};\n\n/**\n * Convert a payload object based on a table schema.\n * Automatically converts strings to number, boolean, Date, JSON if needed.\n */\nexport const convertPayloadByTableSchema = (\n payload: Record<string, any>,\n tableSchema: { name: string; type: string }[]\n): Record<string, any> => {\n const columnTypeMap = Object.fromEntries(\n tableSchema.map(c => [c.name, c.type])\n );\n\n const numericTypes = ['bigint', 'integer', 'smallint', 'numeric', 'decimal'];\n\n const result: Record<string, any> = { ...payload };\n\n for (const [key, value] of Object.entries(payload)) {\n const columnType = columnTypeMap[key];\n if (!columnType || value === null || value === undefined) continue;\n\n switch (columnType) {\n case 'bigint':\n case 'integer':\n case 'smallint':\n case 'numeric':\n case 'decimal':\n result[key] = Number(value);\n break;\n case 'boolean':\n result[key] = value === 'true' || value === '1';\n break;\n case 'timestamp without time zone':\n case 'timestamp with time zone':\n case 'date':\n result[key] = new Date(value);\n break;\n case 'json':\n case 'jsonb':\n try {\n result[key] = typeof value === 'string' ? JSON.parse(value) : value;\n } catch {\n result[key] = value;\n }\n break;\n default:\n // leave as string\n result[key] = value;\n break;\n }\n }\n\n return result;\n}\n\n// check the modelFields with data exists\nexport const validateModelFieldsWithData = (modelFields: any, data: any) => {\n let resultInvalidFields: string[] = []\n\n let modelFieldKeys = modelFields.map((i: any) => i.name)\n\n Object.keys(data).forEach(i => {\n let check = modelFieldKeys.includes(i)\n if (check === false) {\n resultInvalidFields.push(i)\n }\n })\n\n return resultInvalidFields\n}\n\n/**\n * Factory function to create a reusable \"scope\" schema with global validation.\n *\n * @param targetValue - the literal value for the \"target\" field in the scope\n * @returns Zod schema for the scope object with refine logic applied\n */\nexport const createPublicScopeSchema = (targetValue: string) => {\n return z.object({\n // Optional fields, but we ensure they exist for refine check\n isOperator: z.boolean(),\n accountId: z.string().default(\"\"), // default to empty string\n accountCode: z.string().default(\"\"), // default to empty string\n\n // Purpose-specific fields\n target: z.literal(targetValue),\n action: z.string(),\n })\n .refine(\n (data) => (data.accountId?.trim() || data.accountCode?.trim()),\n {\n message: \"Either accountId or accountCode in scope must be provided\",\n path: [], // attach error to the root of the object\n }\n )\n .refine((data) => typeof data.isOperator === \"boolean\", {\n message: \"isOperator must be provided and be a boolean\",\n path: [\"isOperator\"], // attach error to the field\n });\n};\n\n/**\n * Generic helper to extract and normalize scope from a Node.js request body.\n * Ensures accountId and accountCode exist (default to empty string if missing).\n *\n * @param body - the full request body from Node.js (req.body)\n * @returns object compatible with your zod scope schema\n */\nexport const normalizePublicScopeFromBody = (body: any) => {\n const reqScope = body?.scope ?? {};\n return {\n target: reqScope.target,\n action: reqScope.action,\n isOperator: reqScope?.is_operator ?? \"\", // default to empty string if missing\n accountId: reqScope?.account_id ?? \"\", // default to empty string if missing\n accountCode: reqScope?.account_code ?? \"\", // default to empty string if missing\n };\n};"]}
1
+ {"version":3,"file":"schemaUtils.js","sourceRoot":"","sources":["../../src/utils/schemaUtils.ts"],"names":[],"mappings":";;;AACA,6BAAmC;AACnC,mCAAiD;AACjD,mCAAgD;AAEhD;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAC9B,MAAiB,EACjB,SAAsC,QAAQ,EAChD,EAAE,CAAC,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;IAE3D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,eAAe,GAAG,IAAA,6BAAqB,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5D,IAAA,iBAAS,EACL,GAAG,EACH,aAAa,EACb,WAAW,MAAM,EAAE,EACnB,EAAE,EACF,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,EACpC,mBAAW,CAAC,WAAW,CAC1B,CAAC;QACF,OAAO;IACX,CAAC;IAED,oFAAoF;IACpF,sCAAsC;IACrC,GAAW,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAE1D,4BAA4B;IAC5B,sCAAsC;IACtC,WAAW;IACX,uCAAuC;IACvC,IAAI;IAEJ,IAAI,EAAE,CAAC;AACX,CAAC,CAAC;AAhCW,QAAA,kBAAkB,sBAgC7B;AAEF;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CACnC,OAAmD,EACrD,EAAE;IACA,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAA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uBAAuB,2BAsBlC;AAEF;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAAC,IAAS,EAAE,EAAE;IACtD,MAAM,QAAQ,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;IACnC,OAAO;QACH,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,EAAE,WAAW,IAAI,EAAE,EAAK,qCAAqC;QACjF,SAAS,EAAE,QAAQ,EAAE,UAAU,IAAI,EAAE,EAAK,qCAAqC;QAC/E,WAAW,EAAE,QAAQ,EAAE,YAAY,IAAI,EAAE,EAAE,qCAAqC;KACnF,CAAC;AACN,CAAC,CAAC;AATW,QAAA,4BAA4B,gCASvC","sourcesContent":["import { Request, Response, NextFunction } from \"express\";\nimport { z, ZodSchema } from \"zod\";\nimport { sendError, HTTP_STATUS } from \"@/utils\";\nimport { getFormattedZodErrors } from \"@/utils\";\n\n/**\n * Creates a validation middleware from a given Zod schema.\n * @param schema Zod schema to validate against\n * @param source where to validate from (default: \"params\")\n */\nexport const validateWithSchema = (\n schema: ZodSchema,\n source: \"params\" | \"query\" | \"body\" = \"params\"\n) => (req: Request, res: Response, next: NextFunction): void => {\n\n const result = schema.safeParse(req[source]);\n\n if (!result.success) {\n const formattedErrors = getFormattedZodErrors(result.error);\n\n sendError(\n res,\n \"BAD_REQUEST\",\n `Invalid ${source}`,\n \"\",\n `${JSON.stringify(formattedErrors)}`,\n HTTP_STATUS.BAD_REQUEST\n );\n return;\n }\n\n // overwrite request object with parsed+typed data (only matched the validation key)\n // (req as any)[source] = result.data;\n (req as any)[source] = { ...req[source], ...result.data };\n\n // if (source === \"query\") {\n // req.query = result.data as any;\n // } else {\n // req.params = result.data as any;\n // }\n\n next();\n};\n\n/**\n * Middleware to validate multiple schemas in order.\n * @param schemas Array of tuples: [ZodSchema, source]\n */\nexport const validateMultipleSchemas = (\n schemas: [ZodSchema, \"params\" | \"query\" | \"body\"][]\n) => {\n return (req: Request, res: Response, next: NextFunction) => {\n let i = 0;\n\n const runNext = () => {\n if (i >= schemas.length) return next(); // all schemas validated\n\n const [schema, source] = schemas[i];\n i++;\n\n validateWithSchema(schema, source)(req, res, (err) => {\n if (err) return; // already handled by validateWithSchema\n runNext(); // validate next schema\n });\n };\n\n runNext();\n };\n};\n\n/**\n * Convert a payload object based on a table schema.\n * Automatically converts strings to number, boolean, Date, JSON if needed.\n */\nexport const convertPayloadByTableSchema = (\n payload: Record<string, any>,\n tableSchema: { name: string; type: string }[]\n): Record<string, any> => {\n const columnTypeMap = Object.fromEntries(\n tableSchema.map(c => [c.name, c.type])\n );\n\n const numericTypes = ['bigint', 'integer', 'smallint', 'numeric', 'decimal'];\n\n const result: Record<string, any> = { ...payload };\n\n for (const [key, value] of Object.entries(payload)) {\n const columnType = columnTypeMap[key];\n if (!columnType || value === null || value === undefined) continue;\n\n switch (columnType) {\n case 'bigint':\n case 'integer':\n case 'smallint':\n case 'numeric':\n case 'decimal':\n result[key] = Number(value);\n break;\n case 'boolean':\n result[key] = value === 'true' || value === '1';\n break;\n case 'timestamp without time zone':\n case 'timestamp with time zone':\n case 'date':\n result[key] = new Date(value);\n break;\n case 'json':\n case 'jsonb':\n try {\n result[key] = typeof value === 'string' ? JSON.parse(value) : value;\n } catch {\n result[key] = value;\n }\n break;\n default:\n // leave as string\n result[key] = value;\n break;\n }\n }\n\n return result;\n}\n\n// check the modelFields with data exists\nexport const validateModelFieldsWithData = (modelFields: any, data: any) => {\n let resultInvalidFields: string[] = []\n\n let modelFieldKeys = modelFields.map((i: any) => i.name)\n\n Object.keys(data).forEach(i => {\n let check = modelFieldKeys.includes(i)\n if (check === false) {\n resultInvalidFields.push(i)\n }\n })\n\n return resultInvalidFields\n}\n\n/**\n * Factory function to create a reusable \"scope\" schema with global validation.\n *\n * @param targetValue - the literal value for the \"target\" field in the scope\n * @returns Zod schema for the scope object with refine logic applied\n */\nexport const createPublicScopeSchema = (targetValue: string) => {\n return z.object({\n // Optional fields, but we ensure they exist for refine check\n isOperator: z.boolean(),\n accountId: z.string().default(\"\"), // default to empty string\n accountCode: z.string().default(\"\"), // default to empty string\n\n // Purpose-specific fields\n target: z.literal(targetValue),\n action: z.string(),\n })\n .refine(\n (data) => (data.accountId?.trim() || data.accountCode?.trim()),\n {\n message: \"Either accountId or accountCode in scope must be provided\",\n path: [], // attach error to the root of the object\n }\n )\n .refine((data) => typeof data.isOperator === \"boolean\", {\n message: \"isOperator must be provided and be a boolean\",\n path: [\"isOperator\"], // attach error to the field\n });\n};\n\n/**\n * Generic helper to extract and normalize scope from a Node.js request body.\n * Ensures accountId and accountCode exist (default to empty string if missing).\n *\n * @param body - the full request body from Node.js (req.body)\n * @returns object compatible with your zod scope schema\n */\nexport const normalizePublicScopeFromBody = (body: any) => {\n const reqScope = body?.scope ?? {};\n return {\n target: reqScope.target,\n action: reqScope.action,\n isOperator: reqScope?.is_operator ?? \"\", // default to empty string if missing\n accountId: reqScope?.account_id ?? \"\", // default to empty string if missing\n accountCode: reqScope?.account_code ?? \"\", // default to empty string if missing\n };\n};"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storemw-core-api",
3
- "version": "1.0.178",
3
+ "version": "1.0.180",
4
4
  "description": "Storemw Core Api",
5
5
  "main": "dist/app.js",
6
6
  "types": "dist/app.d.ts",
@@ -659,6 +659,51 @@ model document_profiles {
659
659
  country_id BigInt? @default(0)
660
660
  }
661
661
 
662
+ model document_items {
663
+ document_item_id BigInt @id @default(autoincrement())
664
+ createdatetime DateTime? @db.Timestamptz(6)
665
+ createuserid BigInt @default(0)
666
+ updatedatetime DateTime? @db.Timestamptz(6)
667
+ updateuserid BigInt @default(0)
668
+ isdelete Boolean @default(false)
669
+ istrash Boolean @default(false)
670
+ accountid BigInt @default(0)
671
+ document_id BigInt @default(0)
672
+ item_id BigInt @default(0)
673
+ item_name String? @db.VarChar(255)
674
+ code String? @db.VarChar(256)
675
+ description String? @db.VarChar(256)
676
+ unit_amount Decimal? @default(0.0000) @db.Decimal(10, 4)
677
+ quantity Decimal? @default(0.0000) @db.Decimal(10, 4)
678
+ total_amount Decimal? @default(0.0000) @db.Decimal(20, 4)
679
+ uom String? @db.VarChar(256)
680
+ uom_id BigInt? @default(0)
681
+ document_doc_id BigInt?
682
+ }
683
+
684
+ model document_documents {
685
+ document_document_id BigInt @id @default(autoincrement())
686
+ createdatetime DateTime? @db.Timestamptz(6)
687
+ createuserid BigInt @default(0)
688
+ updatedatetime DateTime? @db.Timestamptz(6)
689
+ updateuserid BigInt @default(0)
690
+ isdelete Boolean @default(false)
691
+ istrash Boolean @default(false)
692
+ accountid BigInt @default(0)
693
+ main_document_id BigInt @default(0)
694
+ document_id BigInt @default(0)
695
+ document_number String? @db.VarChar(32)
696
+ document_date DateTime? @db.Date
697
+ document_type String? @db.VarChar(32)
698
+ document_remark String? @db.VarChar(256)
699
+ reference1_id BigInt? @default(0)
700
+ reference1_label String? @db.VarChar(256)
701
+ reference2_id BigInt? @default(0)
702
+ reference2_label String? @db.VarChar(256)
703
+ location_id BigInt @default(0)
704
+ main_document_type String? @db.VarChar(128)
705
+ }
706
+
662
707
  model document_totals {
663
708
  document_total_id BigInt @id @default(autoincrement())
664
709
  createdatetime DateTime? @db.Timestamptz(6)
@@ -1,227 +0,0 @@
1
- import { groups, Prisma } from "@prisma/client";
2
- import { DefaultOmitFields } from "../../lib";
3
- import { DefaultServiceProps } from "../../utils";
4
- declare const primaryKey = "group_id";
5
- export declare const ModelGroupFields: {
6
- createdatetime: "createdatetime";
7
- createuserid: "createuserid";
8
- updatedatetime: "updatedatetime";
9
- updateuserid: "updateuserid";
10
- isdelete: "isdelete";
11
- istrash: "istrash";
12
- accountid: "accountid";
13
- status: "status";
14
- group_id: "group_id";
15
- group_label: "group_label";
16
- group_description: "group_description";
17
- group_type: "group_type";
18
- };
19
- export type ModelGroup = groups;
20
- export type ModelGroupOmitFields = typeof primaryKey | DefaultOmitFields;
21
- export type ModelGroupCreateProps = {
22
- createUserId: number;
23
- data: Omit<Prisma.groupsUncheckedCreateInput, ModelGroupOmitFields>;
24
- };
25
- export type ModelGroupUpdateProps = {
26
- id: number;
27
- updateUserId: number;
28
- data: Omit<Prisma.groupsUncheckedUpdateInput, ModelGroupOmitFields>;
29
- };
30
- export type ModelGroupTrashProps = {
31
- id: number;
32
- updateUserId: number;
33
- };
34
- export type ModelGroupRemoveProps = {
35
- id: number;
36
- updateUserId: number;
37
- };
38
- export type ModelGroupGetProps = {
39
- id: number;
40
- };
41
- export type ModelGroupListProps = {
42
- where?: Prisma.groupsWhereInput;
43
- orderBy?: Prisma.groupsOrderByWithRelationInput | Prisma.groupsOrderByWithRelationInput[];
44
- offset?: number;
45
- limit?: number;
46
- };
47
- export declare const GroupModel: ({ ...rest }: DefaultServiceProps) => {
48
- selectedPrisma: any;
49
- primaryKey: "createdatetime" | "createuserid" | "updatedatetime" | "updateuserid" | "isdelete" | "istrash" | "accountid" | "status" | "group_id" | "group_label" | "group_description" | "group_type";
50
- getFields: (prefix?: string, excludeKeywords?: string[]) => Promise<{
51
- name: string;
52
- type: string;
53
- }[]>;
54
- create: ({ data, }: {
55
- data: Omit<any, DefaultOmitFields>;
56
- }) => Promise<{
57
- createdatetime: Date | null;
58
- createuserid: bigint;
59
- updatedatetime: Date | null;
60
- updateuserid: bigint;
61
- isdelete: boolean | null;
62
- istrash: boolean | null;
63
- accountid: bigint;
64
- status: number | null;
65
- group_id: bigint;
66
- group_label: string | null;
67
- group_description: string | null;
68
- group_type: string | null;
69
- }>;
70
- createMany: ({ dataList, disableRollback, }: {
71
- dataList: Omit<any, DefaultOmitFields>[];
72
- disableRollback?: boolean;
73
- }) => Promise<{
74
- createdatetime: Date | null;
75
- createuserid: bigint;
76
- updatedatetime: Date | null;
77
- updateuserid: bigint;
78
- isdelete: boolean | null;
79
- istrash: boolean | null;
80
- accountid: bigint;
81
- status: number | null;
82
- group_id: bigint;
83
- group_label: string | null;
84
- group_description: string | null;
85
- group_type: string | null;
86
- }[]>;
87
- get: ({ id, where, include, }: {
88
- id?: number;
89
- where?: Record<string, any>;
90
- include?: any;
91
- }) => Promise<{
92
- createdatetime: Date | null;
93
- createuserid: bigint;
94
- updatedatetime: Date | null;
95
- updateuserid: bigint;
96
- isdelete: boolean | null;
97
- istrash: boolean | null;
98
- accountid: bigint;
99
- status: number | null;
100
- group_id: bigint;
101
- group_label: string | null;
102
- group_description: string | null;
103
- group_type: string | null;
104
- } | null>;
105
- list: ({ where, orderBy, offset, limit, include, }?: any) => Promise<{
106
- createdatetime: Date | null;
107
- createuserid: bigint;
108
- updatedatetime: Date | null;
109
- updateuserid: bigint;
110
- isdelete: boolean | null;
111
- istrash: boolean | null;
112
- accountid: bigint;
113
- status: number | null;
114
- group_id: bigint;
115
- group_label: string | null;
116
- group_description: string | null;
117
- group_type: string | null;
118
- }[]>;
119
- count: ({ where, }?: {
120
- where?: Record<string, any>;
121
- }) => Promise<number>;
122
- aggregate: ({ field, operation, where, }: {
123
- field: "createdatetime" | "createuserid" | "updatedatetime" | "updateuserid" | "isdelete" | "istrash" | "accountid" | "status" | "group_id" | "group_label" | "group_description" | "group_type";
124
- operation?: "sum" | "avg" | "min" | "max" | "count";
125
- where?: Record<string, any>;
126
- }) => Promise<number>;
127
- update: ({ id, where, data, disableRollback }: {
128
- id?: number;
129
- where?: Record<string, any>;
130
- data: Partial<{
131
- createdatetime: Date | null;
132
- createuserid: bigint;
133
- updatedatetime: Date | null;
134
- updateuserid: bigint;
135
- isdelete: boolean | null;
136
- istrash: boolean | null;
137
- accountid: bigint;
138
- status: number | null;
139
- group_id: bigint;
140
- group_label: string | null;
141
- group_description: string | null;
142
- group_type: string | null;
143
- }>;
144
- disableRollback?: boolean;
145
- }) => Promise<{
146
- createdatetime: Date | null;
147
- createuserid: bigint;
148
- updatedatetime: Date | null;
149
- updateuserid: bigint;
150
- isdelete: boolean | null;
151
- istrash: boolean | null;
152
- accountid: bigint;
153
- status: number | null;
154
- group_id: bigint;
155
- group_label: string | null;
156
- group_description: string | null;
157
- group_type: string | null;
158
- }>;
159
- updateMany: ({ dataList, disableRollback, }: {
160
- dataList: {
161
- where: Record<string, any>;
162
- data: Partial<{
163
- createdatetime: Date | null;
164
- createuserid: bigint;
165
- updatedatetime: Date | null;
166
- updateuserid: bigint;
167
- isdelete: boolean | null;
168
- istrash: boolean | null;
169
- accountid: bigint;
170
- status: number | null;
171
- group_id: bigint;
172
- group_label: string | null;
173
- group_description: string | null;
174
- group_type: string | null;
175
- }>;
176
- }[];
177
- disableRollback?: boolean;
178
- }) => Promise<{
179
- createdatetime: Date | null;
180
- createuserid: bigint;
181
- updatedatetime: Date | null;
182
- updateuserid: bigint;
183
- isdelete: boolean | null;
184
- istrash: boolean | null;
185
- accountid: bigint;
186
- status: number | null;
187
- group_id: bigint;
188
- group_label: string | null;
189
- group_description: string | null;
190
- group_type: string | null;
191
- }[]>;
192
- trash: ({ ids }: {
193
- ids: number[];
194
- }) => Promise<{
195
- createdatetime: Date | null;
196
- createuserid: bigint;
197
- updatedatetime: Date | null;
198
- updateuserid: bigint;
199
- isdelete: boolean | null;
200
- istrash: boolean | null;
201
- accountid: bigint;
202
- status: number | null;
203
- group_id: bigint;
204
- group_label: string | null;
205
- group_description: string | null;
206
- group_type: string | null;
207
- }[]>;
208
- remove: ({ ids, where }: {
209
- ids?: number[];
210
- where?: Record<string, any>;
211
- }) => Promise<{
212
- createdatetime: Date | null;
213
- createuserid: bigint;
214
- updatedatetime: Date | null;
215
- updateuserid: bigint;
216
- isdelete: boolean | null;
217
- istrash: boolean | null;
218
- accountid: bigint;
219
- status: number | null;
220
- group_id: bigint;
221
- group_label: string | null;
222
- group_description: string | null;
223
- group_type: string | null;
224
- }[]>;
225
- raw: <T = any>(query: string, params?: any[]) => Promise<T[]>;
226
- };
227
- export {};
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GroupModel = exports.ModelGroupFields = void 0;
4
- const lib_1 = require("../../lib");
5
- const primaryKey = "group_id";
6
- exports.ModelGroupFields = (0, lib_1.getFieldsByType)();
7
- const GroupModel = ({ ...rest }) => (0, lib_1.ModelFactory)({
8
- ...rest,
9
- modelName: "groups",
10
- primaryKey
11
- });
12
- exports.GroupModel = GroupModel;
13
- //# sourceMappingURL=GroupModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GroupModel.js","sourceRoot":"","sources":["../../../src/models/group/GroupModel.ts"],"names":[],"mappings":";;;AACA,+BAAyE;AAGzE,MAAM,UAAU,GAAG,UAAU,CAAC;AAEjB,QAAA,gBAAgB,GAAG,IAAA,qBAAe,GAAU,CAAC;AAuCnD,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,IAAI,EAAuB,EAAE,EAAE,CAC3D,IAAA,kBAAY,EAAyD;IACjE,GAAG,IAAI;IACP,SAAS,EAAE,QAAQ;IACnB,UAAU;CACb,CAAC,CAAC;AALM,QAAA,UAAU,cAKhB","sourcesContent":["import { PrismaClient, groups, Prisma } from \"@prisma/client\";\nimport { ModelFactory, DefaultOmitFields, getFieldsByType } from \"@/lib\";\nimport { DefaultServiceProps } from \"@/utils\";\n\nconst primaryKey = \"group_id\";\n\nexport const ModelGroupFields = getFieldsByType<groups>();\n\nexport type ModelGroup = groups\n\nexport type ModelGroupOmitFields = typeof primaryKey | DefaultOmitFields\n\nexport type ModelGroupCreateProps = {\n createUserId: number,\n data: Omit<Prisma.groupsUncheckedCreateInput, ModelGroupOmitFields>\n}\n\nexport type ModelGroupUpdateProps = {\n id: number,\n updateUserId: number,\n data: Omit<Prisma.groupsUncheckedUpdateInput, ModelGroupOmitFields>\n}\n\nexport type ModelGroupTrashProps = {\n id: number,\n updateUserId: number\n}\n\nexport type ModelGroupRemoveProps = {\n id: number,\n updateUserId: number\n}\n\nexport type ModelGroupGetProps = {\n id: number\n}\n\nexport type ModelGroupListProps = {\n where?: Prisma.groupsWhereInput;\n orderBy?: Prisma.groupsOrderByWithRelationInput | Prisma.groupsOrderByWithRelationInput[];\n offset?: number;\n limit?: number;\n};\n\n\nexport const GroupModel = ({ ...rest }: DefaultServiceProps) =>\n ModelFactory<PrismaClient, \"groups\", PrismaClient[\"groups\"], groups>({\n ...rest,\n modelName: \"groups\",\n primaryKey\n });"]}