storemw-core-api 1.0.99 → 1.0.100
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/controllers/reset_password/resetPasswordController.js +2 -0
- package/dist/controllers/reset_password/resetPasswordController.js.map +1 -1
- package/dist/schema/payload/reset_password/schemaResetPassword.d.ts +15 -0
- package/dist/schema/payload/reset_password/schemaResetPassword.js +5 -1
- package/dist/schema/payload/reset_password/schemaResetPassword.js.map +1 -1
- package/dist/services/reset_password/ResetPasswordService.d.ts +2 -0
- package/dist/services/reset_password/ResetPasswordService.js +64 -23
- package/dist/services/reset_password/ResetPasswordService.js.map +1 -1
- package/dist/services/user/UserService.d.ts +5 -2
- package/dist/services/user/UserService.js +86 -3
- package/dist/services/user/UserService.js.map +1 -1
- package/package.json +1 -1
|
@@ -26,6 +26,7 @@ const requestResetPassword = async (req, res, next) => {
|
|
|
26
26
|
},
|
|
27
27
|
payload: {
|
|
28
28
|
resetPassword: {
|
|
29
|
+
userType: reqPayload?.reset_password?.user_type,
|
|
29
30
|
...(reqPayload?.reset_password?.email_address ? { emailAddress: reqPayload?.reset_password?.email_address } : {}),
|
|
30
31
|
...(reqPayload?.reset_password?.mobile_number ? { mobileNumber: reqPayload?.reset_password?.mobile_number } : {}),
|
|
31
32
|
// userId: Number(reqPayload?.access_key?.user_id ?? 0),
|
|
@@ -34,6 +35,7 @@ const requestResetPassword = async (req, res, next) => {
|
|
|
34
35
|
});
|
|
35
36
|
let payload = {
|
|
36
37
|
data: {
|
|
38
|
+
userType: request.payload?.resetPassword?.userType,
|
|
37
39
|
...(request.payload?.resetPassword?.emailAddress ? { emailAddress: request.payload.resetPassword.emailAddress } : {}),
|
|
38
40
|
...(request.payload?.resetPassword?.mobileNumber ? { mobileNumber: request.payload.resetPassword.mobileNumber } : {}),
|
|
39
41
|
// userId: request.payload.resetPassword.userId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetPasswordController.js","sourceRoot":"","sources":["../../../src/controllers/reset_password/resetPasswordController.ts"],"names":[],"mappings":";;;AAEA,mCAAqF;AAErF,yDAAyD;AAEzD,
|
|
1
|
+
{"version":3,"file":"resetPasswordController.js","sourceRoot":"","sources":["../../../src/controllers/reset_password/resetPasswordController.ts"],"names":[],"mappings":";;;AAEA,mCAAqF;AAErF,yDAAyD;AAEzD,yCAAiJ;AACjJ,8CAAgJ;AAEhJ,MAAM,WAAW,GAAG,CAAC,UAAmB,EAAE,EAAE;IAExC,IAAI,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAE/D,OAAO,QAAQ,CAAA;AACnB,CAAC,CAAA;AAED,0DAA0D;AACnD,MAAM,oBAAoB,GAAG,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAgB,EAAE;IACxG,IAAI,CAAC;QAED,MAAM,mBAAmB,GAAG,IAAA,8BAAsB,EAAC,GAAG,CAAC,CAAA;QAEvD,MAAM,oBAAoB,GAAG,IAAA,+BAAoB,EAAC;YAC9C,GAAG,mBAAmB;SACzB,CAAC,CAAA;QAEF,IAAI,QAAQ,GAAQ,EAAE,CAAA;QAEtB,IAAI,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAA;QAC7B,IAAI,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,IAAI,OAAO,GAAG,2CAAiC,CAAC,KAAK,CAAC;YAClD,KAAK,EAAE;gBACH,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;aAC1B;YACD,OAAO,EAAE;gBACL,aAAa,EAAE;oBACX,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS;oBAC/C,GAAG,CAAC,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,C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,EAAC;YAC9C,GAAG,mBAAmB;SACzB,CAAC,CAAA;QAEF,IAAI,QAAQ,GAAQ,EAAE,CAAA;QAEtB,IAAI,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAA;QAC7B,IAAI,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,IAAI,OAAO,GAAG,2CAAiC,CAAC,KAAK,CAAC;YAClD,KAAK,EAAE;gBACH,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;aAC1B;YACD,OAAO,EAAE;gBACL,aAAa,EAAE;oBACX,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa;oBACtD,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY;iBACxD;aACJ;SACJ,CAAC,CAAA;QAEF,IAAI,OAAO,GAA8B;YACrC,IAAI,EAAE;gBACF,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW;gBACtD,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW;aACzD;SACJ,CAAA;QAED,QAAQ,GAAG;YACP,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC,oBAAoB,CAAC,OAAO,CAAC;SACrF,CAAA;QAED,IAAA,mBAAW,EAAC,GAAG,EAAE,QAAQ,EAAE,uCAAuC,CAAC,CAAA;IAEvE,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,CAAA;IACf,CAAC;AACL,CAAC,CAAA;AA3CY,QAAA,oBAAoB,wBA2ChC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\n\nimport { getDefaultServiceProps, sendSuccess, sendError, HTTP_STATUS } from \"@/utils\"\n\n// import { QueryList } from \"@/schema/middleware/route\";\n\nimport { ResetPasswordService, UserType, ResetPasswordRequestProps, ResetPasswordValidateCodeProps, ResetPasswordPerformProps } from \"@/services\"\nimport { schemaResetPasswordRequestPayload, schemaResetPasswordValidateCodePayload, schemaResetPasswordPerformPayload } from \"@/schema/payload\";\n\nconst getRootName = (toSingular: boolean) => {\n\n let rootName = toSingular ? \"resetPassword\" : \"resetPasswords\";\n\n return rootName\n}\n\n/** reset_password/request : request for reset password */\nexport const requestResetPassword = async (req: Request, res: Response, next: NextFunction): Promise<any> => {\n try {\n\n const defaultServiceProps = getDefaultServiceProps(req)\n\n const resetPasswordService = ResetPasswordService({\n ...defaultServiceProps,\n })\n\n let response: any = {}\n\n let reqScope = req.body.scope\n let reqPayload = req.body.payload\n\n let request = schemaResetPasswordRequestPayload.parse({\n scope: {\n target: reqScope.target,\n action: reqScope.action\n },\n payload: {\n resetPassword: {\n userType: reqPayload?.reset_password?.user_type,\n ...(reqPayload?.reset_password?.email_address ? { emailAddress: reqPayload?.reset_password?.email_address } : {}),\n ...(reqPayload?.reset_password?.mobile_number ? { mobileNumber: reqPayload?.reset_password?.mobile_number } : {}),\n // userId: Number(reqPayload?.access_key?.user_id ?? 0),\n }\n }\n })\n\n let payload: ResetPasswordRequestProps = {\n data: {\n userType: request.payload?.resetPassword?.userType as UserType,\n ...(request.payload?.resetPassword?.emailAddress ? { emailAddress: request.payload.resetPassword.emailAddress } : {}),\n ...(request.payload?.resetPassword?.mobileNumber ? { mobileNumber: request.payload.resetPassword.mobileNumber } : {}),\n // userId: request.payload.resetPassword.userId\n }\n }\n\n response = {\n [`${getRootName(true)}`]: await resetPasswordService.requestResetPassword(payload)\n }\n\n sendSuccess(res, response, `Reset password requested successfully`)\n\n } catch (error: any) {\n next(error)\n }\n}\n\n/** reset_password/validate_code : validate reset password code */\nexport const validateResetPasswordCode = async (req: Request, res: Response, next: NextFunction): Promise<any> => {\n try {\n\n const defaultServiceProps = getDefaultServiceProps(req)\n\n const resetPasswordService = ResetPasswordService({\n ...defaultServiceProps,\n })\n\n let response: any = {}\n\n let reqScope = req.body.scope\n let reqPayload = req.body.payload\n\n let request = schemaResetPasswordValidateCodePayload.parse({\n scope: {\n target: reqScope.target,\n action: reqScope.action\n },\n payload: {\n resetPassword: {\n oneTimeCode: reqPayload?.reset_password?.one_time_code ?? \"\",\n }\n }\n })\n\n let payload: ResetPasswordValidateCodeProps = {\n data: {\n oneTimeCode: request.payload?.resetPassword?.oneTimeCode\n }\n }\n\n response = {\n [`${getRootName(true)}`]: await resetPasswordService.validateResetPasscodeCode(payload)\n }\n\n sendSuccess(res, response, `Reset password code validated successfully`)\n\n } catch (error: any) {\n next(error)\n }\n}\n\n/** reset_password/perform : perform for reset password */\nexport const performResetPassword = async (req: Request, res: Response, next: NextFunction): Promise<any> => {\n try {\n\n const defaultServiceProps = getDefaultServiceProps(req)\n\n const resetPasswordService = ResetPasswordService({\n ...defaultServiceProps,\n })\n\n let response: any = {}\n\n let reqScope = req.body.scope\n let reqPayload = req.body.payload\n\n let request = schemaResetPasswordPerformPayload.parse({\n scope: {\n target: reqScope.target,\n action: reqScope.action\n },\n payload: {\n resetPassword: {\n oneTimeCode: reqPayload?.reset_password?.one_time_code,\n newPassword: reqPayload?.reset_password?.new_password,\n }\n }\n })\n\n let payload: ResetPasswordPerformProps = {\n data: {\n oneTimeCode: request.payload.resetPassword.oneTimeCode,\n newPassword: request.payload.resetPassword.newPassword\n }\n }\n\n response = {\n [`${getRootName(true)}`]: await resetPasswordService.performResetPassword(payload)\n }\n\n sendSuccess(res, response, `Reset password performed successfully`)\n\n } catch (error: any) {\n next(error)\n }\n}\n"]}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export declare const UserTypeEnum: z.ZodEnum<[string, ...string[]]>;
|
|
2
3
|
export declare const schemaResetPasswordRequest: z.ZodEffects<z.ZodObject<{
|
|
4
|
+
userType: z.ZodEnum<[string, ...string[]]>;
|
|
3
5
|
emailAddress: z.ZodOptional<z.ZodString>;
|
|
4
6
|
mobileNumber: z.ZodOptional<z.ZodString>;
|
|
5
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
userType: string;
|
|
6
9
|
emailAddress?: string | undefined;
|
|
7
10
|
mobileNumber?: string | undefined;
|
|
8
11
|
}, {
|
|
12
|
+
userType: string;
|
|
9
13
|
emailAddress?: string | undefined;
|
|
10
14
|
mobileNumber?: string | undefined;
|
|
11
15
|
}>, {
|
|
16
|
+
userType: string;
|
|
12
17
|
emailAddress?: string | undefined;
|
|
13
18
|
mobileNumber?: string | undefined;
|
|
14
19
|
}, {
|
|
20
|
+
userType: string;
|
|
15
21
|
emailAddress?: string | undefined;
|
|
16
22
|
mobileNumber?: string | undefined;
|
|
17
23
|
}>;
|
|
@@ -46,28 +52,35 @@ export declare const schemaResetPasswordRequestPayload: z.ZodObject<{
|
|
|
46
52
|
}>;
|
|
47
53
|
payload: z.ZodObject<{
|
|
48
54
|
resetPassword: z.ZodEffects<z.ZodObject<{
|
|
55
|
+
userType: z.ZodEnum<[string, ...string[]]>;
|
|
49
56
|
emailAddress: z.ZodOptional<z.ZodString>;
|
|
50
57
|
mobileNumber: z.ZodOptional<z.ZodString>;
|
|
51
58
|
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
userType: string;
|
|
52
60
|
emailAddress?: string | undefined;
|
|
53
61
|
mobileNumber?: string | undefined;
|
|
54
62
|
}, {
|
|
63
|
+
userType: string;
|
|
55
64
|
emailAddress?: string | undefined;
|
|
56
65
|
mobileNumber?: string | undefined;
|
|
57
66
|
}>, {
|
|
67
|
+
userType: string;
|
|
58
68
|
emailAddress?: string | undefined;
|
|
59
69
|
mobileNumber?: string | undefined;
|
|
60
70
|
}, {
|
|
71
|
+
userType: string;
|
|
61
72
|
emailAddress?: string | undefined;
|
|
62
73
|
mobileNumber?: string | undefined;
|
|
63
74
|
}>;
|
|
64
75
|
}, "strip", z.ZodTypeAny, {
|
|
65
76
|
resetPassword: {
|
|
77
|
+
userType: string;
|
|
66
78
|
emailAddress?: string | undefined;
|
|
67
79
|
mobileNumber?: string | undefined;
|
|
68
80
|
};
|
|
69
81
|
}, {
|
|
70
82
|
resetPassword: {
|
|
83
|
+
userType: string;
|
|
71
84
|
emailAddress?: string | undefined;
|
|
72
85
|
mobileNumber?: string | undefined;
|
|
73
86
|
};
|
|
@@ -79,6 +92,7 @@ export declare const schemaResetPasswordRequestPayload: z.ZodObject<{
|
|
|
79
92
|
};
|
|
80
93
|
payload: {
|
|
81
94
|
resetPassword: {
|
|
95
|
+
userType: string;
|
|
82
96
|
emailAddress?: string | undefined;
|
|
83
97
|
mobileNumber?: string | undefined;
|
|
84
98
|
};
|
|
@@ -90,6 +104,7 @@ export declare const schemaResetPasswordRequestPayload: z.ZodObject<{
|
|
|
90
104
|
};
|
|
91
105
|
payload: {
|
|
92
106
|
resetPassword: {
|
|
107
|
+
userType: string;
|
|
93
108
|
emailAddress?: string | undefined;
|
|
94
109
|
mobileNumber?: string | undefined;
|
|
95
110
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schemaResetPasswordPerformPayload = exports.schemaResetPasswordValidateCodePayload = exports.schemaResetPasswordRequestPayload = exports.schemaResetPasswordPerform = exports.schemaResetPasswordValidateCode = exports.schemaResetPasswordRequest = void 0;
|
|
3
|
+
exports.schemaResetPasswordPerformPayload = exports.schemaResetPasswordValidateCodePayload = exports.schemaResetPasswordRequestPayload = exports.schemaResetPasswordPerform = exports.schemaResetPasswordValidateCode = exports.schemaResetPasswordRequest = exports.UserTypeEnum = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const services_1 = require("../../../services");
|
|
6
|
+
const userTypeValues = Object.values(services_1.userTypes);
|
|
7
|
+
exports.UserTypeEnum = zod_1.z.enum(userTypeValues);
|
|
5
8
|
exports.schemaResetPasswordRequest = zod_1.z.object({
|
|
6
9
|
// userId: z.number(),
|
|
10
|
+
userType: exports.UserTypeEnum,
|
|
7
11
|
emailAddress: zod_1.z.string().optional(),
|
|
8
12
|
mobileNumber: zod_1.z.string().optional()
|
|
9
13
|
}).refine((data) => !!data.emailAddress || !!data.mobileNumber, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaResetPassword.js","sourceRoot":"","sources":["../../../../src/schema/payload/reset_password/schemaResetPassword.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;
|
|
1
|
+
{"version":3,"file":"schemaResetPassword.js","sourceRoot":"","sources":["../../../../src/schema/payload/reset_password/schemaResetPassword.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAIxB,yCAAuC;AAEvC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAS,CAAC,CAAC;AACnC,QAAA,YAAY,GAAG,OAAC,CAAC,IAAI,CAAC,cAAuC,CAAC,CAAC;AAE/D,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,sBAAsB;IACtB,QAAQ,EAAE,oBAAY;IACtB,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EACpD;IACI,OAAO,EAAE,sDAAsD;IAC/D,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,yDAAyD;CACpF,CACJ,CAAC;AAEW,QAAA,+BAA+B,GAAG,OAAC,CAAC,MAAM,CAAC;IACpD,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAA;AAEW,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAA;AAEF,cAAc;AACD,QAAA,iCAAiC,GAAG,OAAC,CAAC,MAAM,CAAC;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC;IACF,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QACd,aAAa,EAAE,kCAA0B;KAC5C,CAAC;CACL,CAAC,CAAC;AAIH,oBAAoB;AACP,QAAA,sCAAsC,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3D,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC;IACF,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QACd,aAAa,EAAE,uCAA+B;KACjD,CAAC;CACL,CAAC,CAAC;AAIH,cAAc;AACD,QAAA,iCAAiC,GAAG,OAAC,CAAC,MAAM,CAAC;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC;IACF,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QACd,aAAa,EAAE,kCAA0B;KAC5C,CAAC;CACL,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { _, dayjs } from \"@/utils\";\n\nimport { userTypes } from \"@/services\";\n\nconst userTypeValues = Object.values(userTypes);\nexport const UserTypeEnum = z.enum(userTypeValues as [string, ...string[]]);\n\nexport const schemaResetPasswordRequest = z.object({\n // userId: z.number(),\n userType: UserTypeEnum,\n emailAddress: z.string().optional(),\n mobileNumber: z.string().optional()\n}).refine(\n (data) => !!data.emailAddress || !!data.mobileNumber,\n {\n message: \"Either emailAddress or mobileNumber must be provided\",\n path: [\"emailAddress\"], // You can also put path: [\"mobileNumber\"] or leave blank\n }\n);\n\nexport const schemaResetPasswordValidateCode = z.object({\n oneTimeCode: z.string()\n})\n\nexport const schemaResetPasswordPerform = z.object({\n oneTimeCode: z.string(),\n newPassword: z.string()\n})\n\n/** Request */\nexport const schemaResetPasswordRequestPayload = z.object({\n scope: z.object({\n target: z.literal(\"reset_password\"),\n action: z.string(),\n }),\n payload: z.object({\n resetPassword: schemaResetPasswordRequest\n })\n});\n\nexport type SchemaResetPasswordRequestPayload = z.infer<typeof schemaResetPasswordRequestPayload>;\n\n/** Validate Code */\nexport const schemaResetPasswordValidateCodePayload = z.object({\n scope: z.object({\n target: z.literal(\"reset_password\"),\n action: z.string(),\n }),\n payload: z.object({\n resetPassword: schemaResetPasswordValidateCode\n })\n});\n\nexport type SchemaResetPasswordValidateCodePayload = z.infer<typeof schemaResetPasswordValidateCodePayload>;\n\n/** Perform */\nexport const schemaResetPasswordPerformPayload = z.object({\n scope: z.object({\n target: z.literal(\"reset_password\"),\n action: z.string(),\n }),\n payload: z.object({\n resetPassword: schemaResetPasswordPerform\n })\n});\n\nexport type SchemaResetPasswordPerformPayload = z.infer<typeof schemaResetPasswordPerformPayload>;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DefaultServiceProps } from "../../utils";
|
|
2
|
+
import { UserType } from "../../services";
|
|
2
3
|
export declare const resetPasswordMethods: {
|
|
3
4
|
readonly email: "email";
|
|
4
5
|
readonly sms: "sms";
|
|
@@ -8,6 +9,7 @@ export type ResetPasswordMethod = typeof resetPasswordMethods[keyof typeof reset
|
|
|
8
9
|
export type ResetPasswordServiceProps = DefaultServiceProps & {};
|
|
9
10
|
export type ResetPasswordRequestProps = {
|
|
10
11
|
data: {
|
|
12
|
+
userType: UserType;
|
|
11
13
|
emailAddress?: string;
|
|
12
14
|
mobileNumber?: string;
|
|
13
15
|
};
|
|
@@ -17,9 +17,18 @@ const ResetPasswordService = (props) => {
|
|
|
17
17
|
const { ...rest } = props;
|
|
18
18
|
// const accessKeyModel = AccessKeyModel({ ...rest })
|
|
19
19
|
// const userService = UserService({ ...rest, userType: "administrator" })
|
|
20
|
-
const userModel =
|
|
20
|
+
// const userModel = UserModel({ ...rest })
|
|
21
21
|
const oneTimeCodeService = (0, services_1.OneTimeCodeService)({ ...rest, field_ref: "user", field_module: "administrator" });
|
|
22
22
|
const requestResetPassword = async ({ data }) => {
|
|
23
|
+
const requestUserType = data.userType ?? "";
|
|
24
|
+
if (!requestUserType) {
|
|
25
|
+
throw new Error(`User Type is required`);
|
|
26
|
+
}
|
|
27
|
+
// validate user type
|
|
28
|
+
const validateUserType = Object.keys(services_1.userTypes).includes(requestUserType);
|
|
29
|
+
if (validateUserType === false) {
|
|
30
|
+
throw new Error(`Invalid user type: ${requestUserType}`);
|
|
31
|
+
}
|
|
23
32
|
// get the onSetup from hook
|
|
24
33
|
const hookSetup = features_1.ResetPasswordHook.onSetup();
|
|
25
34
|
const codeType = hookSetup.oneTimeCodeType;
|
|
@@ -27,6 +36,7 @@ const ResetPasswordService = (props) => {
|
|
|
27
36
|
const emailAddress = data?.emailAddress ?? "";
|
|
28
37
|
const mobileNumber = data?.mobileNumber ?? "";
|
|
29
38
|
let user = {};
|
|
39
|
+
const globalUserService = (0, services_1.UserService)({ ...rest, userType: requestUserType });
|
|
30
40
|
if (!resetPasswordMethod) {
|
|
31
41
|
throw new Error(`Invalid reset password method: ${hookSetup?.resetPasswordMethod ?? ""}`);
|
|
32
42
|
}
|
|
@@ -35,19 +45,34 @@ const ResetPasswordService = (props) => {
|
|
|
35
45
|
throw new Error(`Invalid email address: ${emailAddress}`);
|
|
36
46
|
}
|
|
37
47
|
// get the user by email
|
|
38
|
-
let dataUser = await
|
|
39
|
-
offset: 0,
|
|
48
|
+
let { data: dataUser } = await globalUserService.listUsers({
|
|
40
49
|
limit: 1,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
offset: 0,
|
|
51
|
+
filters: [
|
|
52
|
+
{
|
|
53
|
+
field: `${models_1.ModelUserFields.email}`,
|
|
54
|
+
operator: "=",
|
|
55
|
+
value: `${emailAddress}`
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
sortfield: `${models_1.ModelUserFields.user_id}`,
|
|
59
|
+
sortorder: "ASC",
|
|
60
|
+
includePassword: false,
|
|
61
|
+
datatypes: []
|
|
50
62
|
});
|
|
63
|
+
// let dataUser = await userModel.list({
|
|
64
|
+
// offset: 0,
|
|
65
|
+
// limit: 1,
|
|
66
|
+
// where: {
|
|
67
|
+
// [`${ModelUserFields.email}`]: `${emailAddress}`,
|
|
68
|
+
// [`${ModelUserFields.isdelete}`]: false,
|
|
69
|
+
// [`${ModelUserFields.istrash}`]: false,
|
|
70
|
+
// },
|
|
71
|
+
// orderBy: {
|
|
72
|
+
// [`${ModelUserFields.user_id}`]: "asc"
|
|
73
|
+
// },
|
|
74
|
+
// include: []
|
|
75
|
+
// })
|
|
51
76
|
user = dataUser.length > 0 ? dataUser[0] : {};
|
|
52
77
|
}
|
|
53
78
|
if (resetPasswordMethod === "sms" || resetPasswordMethod === "whatapps") {
|
|
@@ -55,19 +80,35 @@ const ResetPasswordService = (props) => {
|
|
|
55
80
|
throw new Error(`Invalid mobile number: ${mobileNumber}`);
|
|
56
81
|
}
|
|
57
82
|
// get the user by contact
|
|
58
|
-
let dataUser = await
|
|
59
|
-
offset: 0,
|
|
83
|
+
let { data: dataUser } = await globalUserService.listUsers({
|
|
60
84
|
limit: 1,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
offset: 0,
|
|
86
|
+
filters: [
|
|
87
|
+
{
|
|
88
|
+
field: `${models_1.ModelUserFields.contact}`,
|
|
89
|
+
operator: "=",
|
|
90
|
+
value: `${mobileNumber}`
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
sortfield: `${models_1.ModelUserFields.user_id}`,
|
|
94
|
+
sortorder: "ASC",
|
|
95
|
+
includePassword: false,
|
|
96
|
+
datatypes: []
|
|
70
97
|
});
|
|
98
|
+
// get the user by contact
|
|
99
|
+
// let dataUser = await userModel.list({
|
|
100
|
+
// offset: 0,
|
|
101
|
+
// limit: 1,
|
|
102
|
+
// where: {
|
|
103
|
+
// [`${ModelUserFields.contact}`]: `${mobileNumber}`,
|
|
104
|
+
// [`${ModelUserFields.isdelete}`]: false,
|
|
105
|
+
// [`${ModelUserFields.istrash}`]: false,
|
|
106
|
+
// },
|
|
107
|
+
// orderBy: {
|
|
108
|
+
// [`${ModelUserFields.user_id}`]: "asc"
|
|
109
|
+
// },
|
|
110
|
+
// include: []
|
|
111
|
+
// })
|
|
71
112
|
user = dataUser.length > 0 ? dataUser[0] : {};
|
|
72
113
|
}
|
|
73
114
|
if (emailAddress === "" && mobileNumber === "") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResetPasswordService.js","sourceRoot":"","sources":["../../../src/services/reset_password/ResetPasswordService.ts"],"names":[],"mappings":";;;AAAA,mCAAkH;AAElH,yDAAyD;AAEzD,oIAAoI;AAEpI,mCAAgC;AAEhC,qCAA8E;AAC9E,yCAAiJ;AAEjJ,yCAA8C;AAEjC,QAAA,oBAAoB,GAAG;IAChC,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;CACd,CAAA;AA2BH,MAAM,oBAAoB,GAAG,CAAC,KAAgC,EAAE,EAAE;IAErE,MAAM,EACF,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,qDAAqD;IACrD,0EAA0E;IAC1E,MAAM,SAAS,GAAG,IAAA,kBAAS,EAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IACxC,MAAM,kBAAkB,GA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AAC;YACtD,EAAE,EAAE,MAAM;YACV,IAAI,EAAE;gBACF,mBAAmB,EAAE,WAAW;aACnC;YACD,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;SACvC,CAAC,CAAA;QAEF,wCAAwC;QACxC,IAAI,4BAAiB,CAAC,SAAS,EAAE,CAAC;YAE9B,MAAM,kBAAkB,GAAG,MAAM,4BAAiB,CAAC,SAAS,CAAC;gBACzD,MAAM;gBACN,QAAQ;gBACR,mBAAmB;gBACnB,WAAW;gBACX,IAAI;aACP,CAAC,CAAA;YAEF,iBAAiB,GAAG,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;QAE5E,CAAC;QAED,OAAO;YACH,GAAG,iBAAiB;YACpB,kBAAkB,EAAE,eAAe;SACtC,CAAA;IACL,CAAC,CAAA;IAED,OAAO;QACH,oBAAoB;QACpB,yBAAyB;QACzB,oBAAoB;KACvB,CAAA;AAEL,CAAC,CAAA;AA5RY,QAAA,oBAAoB,wBA4RhC","sourcesContent":["import { DefaultServiceProps, validateFormatEmailAddress, validateFormatMobileNumber, throwError } from \"@/utils\";\n\n// import { QueryList, QueryGet } from \"@/schema/common\";\n\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from \"@/lib\";\n\nimport { dayjs } from \"@/utils\";\n\nimport { ModelOneTimeCodeFields, ModelUserFields, UserModel } from \"@/models\";\nimport { UserService, OneTimeCodeService, OneTimeCodeType, OneTimeCodeCreateProps, oneTimeCodeStatus, oneTimeCodePurposeTypes } from \"@/services\"\n\nimport { ResetPasswordHook } from \"@/features\"\n\nexport const resetPasswordMethods = {\n email: \"email\",\n sms: \"sms\",\n whatapps: \"whatapps\",\n} as const\n\nexport type ResetPasswordMethod = typeof resetPasswordMethods[keyof typeof resetPasswordMethods]\n\nexport type ResetPasswordServiceProps = DefaultServiceProps & {\n};\n\nexport type ResetPasswordRequestProps = {\n data: {\n emailAddress?: string\n mobileNumber?: string\n }\n}\n\nexport type ResetPasswordValidateCodeProps = {\n data: {\n oneTimeCode: string\n }\n}\n\nexport type ResetPasswordPerformProps = {\n data: {\n oneTimeCode: string\n newPassword: string\n }\n}\n\nexport const ResetPasswordService = (props: ResetPasswordServiceProps) => {\n\n const {\n ...rest\n } = props\n\n // const accessKeyModel = AccessKeyModel({ ...rest })\n // const userService = UserService({ ...rest, userType: \"administrator\" })\n const userModel = UserModel({ ...rest })\n const oneTimeCodeService = OneTimeCodeService({ ...rest, field_ref: \"user\", field_module: \"administrator\" })\n\n const requestResetPassword = async ({ data }: ResetPasswordRequestProps) => {\n\n // get the onSetup from hook\n const hookSetup = ResetPasswordHook.onSetup()\n\n const codeType: OneTimeCodeType = hookSetup.oneTimeCodeType\n const resetPasswordMethod: ResetPasswordMethod = hookSetup.resetPasswordMethod\n const emailAddress = data?.emailAddress ?? \"\"\n const mobileNumber = data?.mobileNumber ?? \"\"\n\n let user: any = {}\n\n if (!resetPasswordMethod) {\n throw new Error(`Invalid reset password method: ${hookSetup?.resetPasswordMethod ?? \"\"}`);\n }\n\n if (resetPasswordMethod === \"email\") {\n if (validateFormatEmailAddress(emailAddress) === false) {\n throw new Error(`Invalid email address: ${emailAddress}`);\n }\n\n // get the user by email\n let dataUser = await userModel.list({\n offset: 0,\n limit: 1,\n where: {\n [`${ModelUserFields.email}`]: `${emailAddress}`,\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false,\n },\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: []\n })\n\n user = dataUser.length > 0 ? dataUser[0] : {}\n\n }\n\n if (resetPasswordMethod === \"sms\" || resetPasswordMethod === \"whatapps\") {\n if (validateFormatMobileNumber(mobileNumber) === false) {\n throw new Error(`Invalid mobile number: ${mobileNumber}`);\n }\n\n // get the user by contact\n let dataUser = await userModel.list({\n offset: 0,\n limit: 1,\n where: {\n [`${ModelUserFields.contact}`]: `${mobileNumber}`,\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false,\n },\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: []\n })\n\n user = dataUser.length > 0 ? dataUser[0] : {}\n\n }\n\n if (emailAddress === \"\" && mobileNumber === \"\") {\n throw new Error(`Either email address or mobile number is required`);\n }\n\n // verify the user\n if (!user?.user_id) {\n throw new Error(`Cannot find the user by ${resetPasswordMethod}: ${emailAddress ? emailAddress : mobileNumber}`);\n }\n\n // verify the user active\n if (Boolean(user?.status) === false) {\n throw new Error(`User is invalid status: ${user?.user_id ?? 0}`);\n }\n\n const userId = Number(user?.user_id ?? 0)\n const userType = user?.user_type ?? \"\"\n\n const codePayload: OneTimeCodeCreateProps = {\n field_ref: \"user\",\n field_module: userType,\n data: {\n purposeType: \"reset_password\",\n codeType,\n emailAddress,\n mobileNumber,\n userId,\n userType\n }\n }\n\n // generate the code \n const oneTimeCode = await oneTimeCodeService.createOneTimeCode(codePayload)\n\n // console.log('oneTimeCode', oneTimeCode)\n\n let responseOneTimeCode = await oneTimeCodeService.getOneTimeCode({ id: Number(oneTimeCode?.one_time_code_id ?? 0), datatypes: [] })\n\n // Call the consumer hook, if registered\n if (ResetPasswordHook.onRequest) {\n\n const responseCustomHook = await ResetPasswordHook.onRequest({\n userId,\n userType,\n resetPasswordMethod,\n emailAddress,\n mobileNumber,\n oneTimeCode: oneTimeCode?.code ?? \"\",\n user\n })\n\n responseOneTimeCode = { ...responseOneTimeCode, custom: responseCustomHook }\n\n }\n\n return responseOneTimeCode\n }\n\n const validateResetPasscodeCode = async ({ data }: ResetPasswordValidateCodeProps) => {\n\n const oneTimeCode = data.oneTimeCode ?? \"\"\n\n if (!oneTimeCode) {\n throw new Error(`Reset passcode code cannot be empty`);\n }\n\n // check code exist\n const { data: existOneTimeCodes } = await oneTimeCodeService.listOneTimeCodes({\n limit: 1,\n offset: 0,\n filters: [\n {\n field: `${ModelOneTimeCodeFields.code}`,\n operator: \"=\",\n value: `${oneTimeCode}`\n },\n {\n field: `${ModelOneTimeCodeFields.purpose_type}`,\n operator: \"=\",\n value: `${oneTimeCodePurposeTypes.reset_password}`\n },\n ],\n sortfield: `${ModelOneTimeCodeFields.one_time_code_id}`,\n sortorder: \"ASC\",\n datatypes: [],\n revealCode: true // return the code as well\n })\n\n if (existOneTimeCodes.length <= 0) {\n throw new Error(`Invalid reset password code: ${oneTimeCode}`);\n }\n\n const existOneTimeCode = existOneTimeCodes[0]\n\n // check is not used before\n if (existOneTimeCode?.code_status !== oneTimeCodeStatus.active) {\n throw new Error(`Reset password code is not active/used: ${oneTimeCode}`);\n }\n\n const expiresAt = dayjs(existOneTimeCode?.expires_at)\n const codeIsExpired = dayjs().isAfter(expiresAt)\n\n // check code is expired\n if (codeIsExpired) {\n throw new Error(`Reset password code is expired: ${oneTimeCode}`);\n }\n\n // console.log('existOneTimeCode', existOneTimeCode)\n\n return existOneTimeCode\n }\n\n const performResetPassword = async ({ data }: ResetPasswordPerformProps) => {\n\n // get the onSetup from hook\n const hookSetup = ResetPasswordHook.onSetup()\n\n // const codeType: OneTimeCodeType = hookSetup.oneTimeCodeType\n const resetPasswordMethod: ResetPasswordMethod = hookSetup.resetPasswordMethod\n const oneTimeCode = data?.oneTimeCode ?? \"\"\n const newPassword = data?.newPassword ?? \"\"\n\n if (!oneTimeCode) {\n throw new Error(`One Time Code is required`);\n }\n\n if (!newPassword) {\n throw new Error(`New password is required`);\n }\n\n // validate the one time code\n const validateOneTimeCode = await validateResetPasscodeCode({ data: { oneTimeCode } })\n\n // retrieve the user by the one time code\n const oneTimeCodeUserId = validateOneTimeCode?.user_id ?? \"\"\n const oneTimeCodeUserType = validateOneTimeCode?.user_type ?? \"\"\n\n if (!oneTimeCodeUserId) {\n throw new Error(`Invalid one time code userId: ${oneTimeCode}`);\n }\n\n if (!oneTimeCodeUserType) {\n throw new Error(`Invalid one time code userId Type: ${oneTimeCode}`);\n }\n\n // retrive the user information\n const userService = UserService({ ...rest, userType: oneTimeCodeUserType })\n const user = await userService.getUser({ id: Number(oneTimeCodeUserId), datatypes: [] })\n\n // verify the user\n if (!user?.user_id) {\n throw new Error(`Cannot find the userId: ${Number(oneTimeCodeUserId)}`);\n }\n\n // verify the user active\n if (Boolean(user?.status) === false) {\n throw new Error(`User is invalid status: ${user?.user_id ?? 0}`);\n }\n\n const userId = Number(user?.user_id ?? 0)\n const userType = user?.user_type ?? \"\"\n\n // consume the one time code\n let responseConsume = await oneTimeCodeService.consumeOneTimeCode({\n field_ref: \"user\",\n field_module: userType,\n data: {\n oneTimeCode,\n purposeType: \"reset_password\",\n userId,\n userType\n }\n })\n\n // change password for user\n let responseOnSuccess = await userService.replacePassword({\n id: userId,\n data: {\n unhashLoginPassword: newPassword\n },\n isOperator: Boolean(rest.isOperator)\n })\n\n // Call the consumer hook, if registered\n if (ResetPasswordHook.onSuccess) {\n\n const responseCustomHook = await ResetPasswordHook.onSuccess({\n userId,\n userType,\n resetPasswordMethod,\n oneTimeCode,\n user\n })\n\n responseOnSuccess = { ...responseOnSuccess, custom: responseCustomHook }\n\n }\n\n return {\n ...responseOnSuccess,\n consumeOneTimeCode: responseConsume\n }\n }\n\n return {\n requestResetPassword,\n validateResetPasscodeCode,\n performResetPassword\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"ResetPasswordService.js","sourceRoot":"","sources":["../../../src/services/reset_password/ResetPasswordService.ts"],"names":[],"mappings":";;;AAAA,mCAAkH;AAElH,yDAAyD;AAEzD,oIAAoI;AAEpI,mCAAgC;AAEhC,qCAAmE;AACnE,yCAAsK;AAEtK,yCAA8C;AAEjC,QAAA,oBAAoB,GAAG;IAChC,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;CACd,CAAA;AA4BH,MAAM,oBAAoB,GAAG,CAAC,KAAgC,EAAE,EAAE;IAErE,MAAM,EACF,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,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AiB,GAAG,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;QAE5E,CAAC;QAED,OAAO;YACH,GAAG,iBAAiB;YACpB,kBAAkB,EAAE,eAAe;SACtC,CAAA;IACL,CAAC,CAAA;IAED,OAAO;QACH,oBAAoB;QACpB,yBAAyB;QACzB,oBAAoB;KACvB,CAAA;AAEL,CAAC,CAAA;AA3UY,QAAA,oBAAoB,wBA2UhC","sourcesContent":["import { DefaultServiceProps, validateFormatEmailAddress, validateFormatMobileNumber, throwError } from \"@/utils\";\n\n// import { QueryList, QueryGet } from \"@/schema/common\";\n\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from \"@/lib\";\n\nimport { dayjs } from \"@/utils\";\n\nimport { ModelOneTimeCodeFields, ModelUserFields } from \"@/models\";\nimport { UserService, UserType, userTypes, OneTimeCodeService, OneTimeCodeType, OneTimeCodeCreateProps, oneTimeCodeStatus, oneTimeCodePurposeTypes } from \"@/services\"\n\nimport { ResetPasswordHook } from \"@/features\"\n\nexport const resetPasswordMethods = {\n email: \"email\",\n sms: \"sms\",\n whatapps: \"whatapps\",\n} as const\n\nexport type ResetPasswordMethod = typeof resetPasswordMethods[keyof typeof resetPasswordMethods]\n\nexport type ResetPasswordServiceProps = DefaultServiceProps & {\n};\n\nexport type ResetPasswordRequestProps = {\n data: {\n userType: UserType\n emailAddress?: string\n mobileNumber?: string\n }\n}\n\nexport type ResetPasswordValidateCodeProps = {\n data: {\n oneTimeCode: string\n }\n}\n\nexport type ResetPasswordPerformProps = {\n data: {\n oneTimeCode: string\n newPassword: string\n }\n}\n\nexport const ResetPasswordService = (props: ResetPasswordServiceProps) => {\n\n const {\n ...rest\n } = props\n\n // const accessKeyModel = AccessKeyModel({ ...rest })\n // const userService = UserService({ ...rest, userType: \"administrator\" })\n // const userModel = UserModel({ ...rest })\n const oneTimeCodeService = OneTimeCodeService({ ...rest, field_ref: \"user\", field_module: \"administrator\" })\n\n const requestResetPassword = async ({ data }: ResetPasswordRequestProps) => {\n\n const requestUserType = data.userType ?? \"\"\n\n if (!requestUserType) {\n throw new Error(`User Type is required`);\n }\n\n // validate user type\n const validateUserType = Object.keys(userTypes).includes(requestUserType)\n\n if (validateUserType === false) {\n throw new Error(`Invalid user type: ${requestUserType}`);\n }\n\n // get the onSetup from hook\n const hookSetup = ResetPasswordHook.onSetup()\n\n const codeType: OneTimeCodeType = hookSetup.oneTimeCodeType\n const resetPasswordMethod: ResetPasswordMethod = hookSetup.resetPasswordMethod\n const emailAddress = data?.emailAddress ?? \"\"\n const mobileNumber = data?.mobileNumber ?? \"\"\n\n let user: any = {}\n\n const globalUserService = UserService({ ...rest, userType: requestUserType })\n\n if (!resetPasswordMethod) {\n throw new Error(`Invalid reset password method: ${hookSetup?.resetPasswordMethod ?? \"\"}`);\n }\n\n if (resetPasswordMethod === \"email\") {\n if (validateFormatEmailAddress(emailAddress) === false) {\n throw new Error(`Invalid email address: ${emailAddress}`);\n }\n\n // get the user by email\n let { data: dataUser } = await globalUserService.listUsers({\n limit: 1,\n offset: 0,\n filters: [\n {\n field: `${ModelUserFields.email}`,\n operator: \"=\",\n value: `${emailAddress}`\n }\n ],\n sortfield: `${ModelUserFields.user_id}`,\n sortorder: \"ASC\",\n includePassword: false,\n datatypes: []\n })\n // let dataUser = await userModel.list({\n // offset: 0,\n // limit: 1,\n // where: {\n // [`${ModelUserFields.email}`]: `${emailAddress}`,\n // [`${ModelUserFields.isdelete}`]: false,\n // [`${ModelUserFields.istrash}`]: false,\n // },\n // orderBy: {\n // [`${ModelUserFields.user_id}`]: \"asc\"\n // },\n // include: []\n // })\n\n user = dataUser.length > 0 ? dataUser[0] : {}\n\n }\n\n if (resetPasswordMethod === \"sms\" || resetPasswordMethod === \"whatapps\") {\n if (validateFormatMobileNumber(mobileNumber) === false) {\n throw new Error(`Invalid mobile number: ${mobileNumber}`);\n }\n\n // get the user by contact\n let { data: dataUser } = await globalUserService.listUsers({\n limit: 1,\n offset: 0,\n filters: [\n {\n field: `${ModelUserFields.contact}`,\n operator: \"=\",\n value: `${mobileNumber}`\n }\n ],\n sortfield: `${ModelUserFields.user_id}`,\n sortorder: \"ASC\",\n includePassword: false,\n datatypes: []\n })\n\n // get the user by contact\n // let dataUser = await userModel.list({\n // offset: 0,\n // limit: 1,\n // where: {\n // [`${ModelUserFields.contact}`]: `${mobileNumber}`,\n // [`${ModelUserFields.isdelete}`]: false,\n // [`${ModelUserFields.istrash}`]: false,\n // },\n // orderBy: {\n // [`${ModelUserFields.user_id}`]: \"asc\"\n // },\n // include: []\n // })\n\n user = dataUser.length > 0 ? dataUser[0] : {}\n\n }\n\n if (emailAddress === \"\" && mobileNumber === \"\") {\n throw new Error(`Either email address or mobile number is required`);\n }\n\n // verify the user\n if (!user?.user_id) {\n throw new Error(`Cannot find the user by ${resetPasswordMethod}: ${emailAddress ? emailAddress : mobileNumber}`);\n }\n\n // verify the user active\n if (Boolean(user?.status) === false) {\n throw new Error(`User is invalid status: ${user?.user_id ?? 0}`);\n }\n\n const userId = Number(user?.user_id ?? 0)\n const userType = user?.user_type ?? \"\"\n\n const codePayload: OneTimeCodeCreateProps = {\n field_ref: \"user\",\n field_module: userType,\n data: {\n purposeType: \"reset_password\",\n codeType,\n emailAddress,\n mobileNumber,\n userId,\n userType\n }\n }\n\n // generate the code \n const oneTimeCode = await oneTimeCodeService.createOneTimeCode(codePayload)\n\n // console.log('oneTimeCode', oneTimeCode)\n\n let responseOneTimeCode = await oneTimeCodeService.getOneTimeCode({ id: Number(oneTimeCode?.one_time_code_id ?? 0), datatypes: [] })\n\n // Call the consumer hook, if registered\n if (ResetPasswordHook.onRequest) {\n\n const responseCustomHook = await ResetPasswordHook.onRequest({\n userId,\n userType,\n resetPasswordMethod,\n emailAddress,\n mobileNumber,\n oneTimeCode: oneTimeCode?.code ?? \"\",\n user\n })\n\n responseOneTimeCode = { ...responseOneTimeCode, custom: responseCustomHook }\n\n }\n\n return responseOneTimeCode\n }\n\n const validateResetPasscodeCode = async ({ data }: ResetPasswordValidateCodeProps) => {\n\n const oneTimeCode = data.oneTimeCode ?? \"\"\n\n if (!oneTimeCode) {\n throw new Error(`Reset passcode code cannot be empty`);\n }\n\n // check code exist\n const { data: existOneTimeCodes } = await oneTimeCodeService.listOneTimeCodes({\n limit: 1,\n offset: 0,\n filters: [\n {\n field: `${ModelOneTimeCodeFields.code}`,\n operator: \"=\",\n value: `${oneTimeCode}`\n },\n {\n field: `${ModelOneTimeCodeFields.purpose_type}`,\n operator: \"=\",\n value: `${oneTimeCodePurposeTypes.reset_password}`\n },\n ],\n sortfield: `${ModelOneTimeCodeFields.one_time_code_id}`,\n sortorder: \"ASC\",\n datatypes: [],\n revealCode: true // return the code as well\n })\n\n if (existOneTimeCodes.length <= 0) {\n throw new Error(`Invalid reset password code: ${oneTimeCode}`);\n }\n\n const existOneTimeCode = existOneTimeCodes[0]\n\n // check is not used before\n if (existOneTimeCode?.code_status !== oneTimeCodeStatus.active) {\n throw new Error(`Reset password code is not active/used: ${oneTimeCode}`);\n }\n\n const expiresAt = dayjs(existOneTimeCode?.expires_at)\n const codeIsExpired = dayjs().isAfter(expiresAt)\n\n // check code is expired\n if (codeIsExpired) {\n throw new Error(`Reset password code is expired: ${oneTimeCode}`);\n }\n\n // console.log('existOneTimeCode', existOneTimeCode)\n\n return existOneTimeCode\n }\n\n const performResetPassword = async ({ data }: ResetPasswordPerformProps) => {\n\n // get the onSetup from hook\n const hookSetup = ResetPasswordHook.onSetup()\n\n // const codeType: OneTimeCodeType = hookSetup.oneTimeCodeType\n const resetPasswordMethod: ResetPasswordMethod = hookSetup.resetPasswordMethod\n const oneTimeCode = data?.oneTimeCode ?? \"\"\n const newPassword = data?.newPassword ?? \"\"\n\n if (!oneTimeCode) {\n throw new Error(`One Time Code is required`);\n }\n\n if (!newPassword) {\n throw new Error(`New password is required`);\n }\n\n // validate the one time code\n const validateOneTimeCode = await validateResetPasscodeCode({ data: { oneTimeCode } })\n\n // retrieve the user by the one time code\n const oneTimeCodeUserId = validateOneTimeCode?.user_id ?? \"\"\n const oneTimeCodeUserType = validateOneTimeCode?.user_type ?? \"\"\n\n if (!oneTimeCodeUserId) {\n throw new Error(`Invalid one time code userId: ${oneTimeCode}`);\n }\n\n if (!oneTimeCodeUserType) {\n throw new Error(`Invalid one time code userId Type: ${oneTimeCode}`);\n }\n\n // retrive the user information\n const userService = UserService({ ...rest, userType: oneTimeCodeUserType })\n const user = await userService.getUser({ id: Number(oneTimeCodeUserId), datatypes: [] })\n\n // verify the user\n if (!user?.user_id) {\n throw new Error(`Cannot find the userId: ${Number(oneTimeCodeUserId)}`);\n }\n\n // verify the user active\n if (Boolean(user?.status) === false) {\n throw new Error(`User is invalid status: ${user?.user_id ?? 0}`);\n }\n\n const userId = Number(user?.user_id ?? 0)\n const userType = user?.user_type ?? \"\"\n\n // consume the one time code\n let responseConsume = await oneTimeCodeService.consumeOneTimeCode({\n field_ref: \"user\",\n field_module: userType,\n data: {\n oneTimeCode,\n purposeType: \"reset_password\",\n userId,\n userType\n }\n })\n\n // change password for user\n let responseOnSuccess = await userService.replacePassword({\n id: userId,\n data: {\n unhashLoginPassword: newPassword\n },\n isOperator: Boolean(rest.isOperator)\n })\n\n // Call the consumer hook, if registered\n if (ResetPasswordHook.onSuccess) {\n\n const responseCustomHook = await ResetPasswordHook.onSuccess({\n userId,\n userType,\n resetPasswordMethod,\n oneTimeCode,\n user\n })\n\n responseOnSuccess = { ...responseOnSuccess, custom: responseCustomHook }\n\n }\n\n return {\n ...responseOnSuccess,\n consumeOneTimeCode: responseConsume\n }\n }\n\n return {\n requestResetPassword,\n validateResetPasscodeCode,\n performResetPassword\n }\n\n}\n\n"]}
|
|
@@ -27,9 +27,12 @@ export type UserGetProps = QueryGet & {
|
|
|
27
27
|
overrideUserType?: UserType | "";
|
|
28
28
|
includePassword?: boolean;
|
|
29
29
|
skipFilterAccountId?: boolean;
|
|
30
|
+
skipFilterUserType?: boolean;
|
|
30
31
|
};
|
|
31
32
|
export type UserListProps = QueryList & {
|
|
32
33
|
includePassword?: boolean;
|
|
34
|
+
skipFilterAccountId?: boolean;
|
|
35
|
+
skipFilterUserType?: boolean;
|
|
33
36
|
};
|
|
34
37
|
export type UserRemoveProps = {
|
|
35
38
|
ids: BigInt[];
|
|
@@ -121,8 +124,8 @@ export type UserReplacePasswordProps = {
|
|
|
121
124
|
export declare const UserService: (props: UserServiceProps) => {
|
|
122
125
|
createUser: ({ data, userType: overrideUserType }: UserCreateProps) => Promise<any>;
|
|
123
126
|
updateUser: ({ id, data, userType: overrideUserType }: UserUpdateProps) => Promise<any>;
|
|
124
|
-
getUser: ({ id, datatypes, includePassword, overrideUserType, skipFilterAccountId }: UserGetProps) => Promise<any>;
|
|
125
|
-
listUsers: ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword }: UserListProps) => Promise<{
|
|
127
|
+
getUser: ({ id, datatypes, includePassword, overrideUserType, skipFilterAccountId, skipFilterUserType }: UserGetProps) => Promise<any>;
|
|
128
|
+
listUsers: ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword, skipFilterAccountId, skipFilterUserType }: UserListProps) => Promise<{
|
|
126
129
|
data: any[];
|
|
127
130
|
total: number;
|
|
128
131
|
}>;
|
|
@@ -9,6 +9,7 @@ const WorkerService_1 = require("./WorkerService");
|
|
|
9
9
|
const DriverService_1 = require("./DriverService");
|
|
10
10
|
const RetailerService_1 = require("./RetailerService");
|
|
11
11
|
const MemberService_1 = require("./MemberService");
|
|
12
|
+
const lib_1 = require("../../lib");
|
|
12
13
|
const utils_1 = require("../../utils");
|
|
13
14
|
const utils_2 = require("../../utils");
|
|
14
15
|
const OperatorService_1 = require("./OperatorService");
|
|
@@ -22,6 +23,26 @@ exports.userTypes = {
|
|
|
22
23
|
retailer: "retailer",
|
|
23
24
|
member: "member",
|
|
24
25
|
};
|
|
26
|
+
let mainSqlSelect = {
|
|
27
|
+
[`usr.${models_1.ModelUserFields.user_id}`]: "user_id",
|
|
28
|
+
[`usr.${models_1.ModelUserFields.user_type}`]: "user_type",
|
|
29
|
+
[`usr.${models_1.ModelUserFields.login_username}`]: "username",
|
|
30
|
+
[`usr.${models_1.ModelUserFields.firstname}`]: "firstname",
|
|
31
|
+
[`usr.${models_1.ModelUserFields.lastname}`]: "lastname",
|
|
32
|
+
[`usr.${models_1.ModelUserFields.contact}`]: "contact",
|
|
33
|
+
[`usr.${models_1.ModelUserFields.email}`]: "email",
|
|
34
|
+
[`usr.${models_1.ModelUserFields.address}`]: "address",
|
|
35
|
+
[`usr.${models_1.ModelUserFields.status}`]: "status",
|
|
36
|
+
};
|
|
37
|
+
let defaultSqlSelect = {
|
|
38
|
+
[`usr.${models_1.ModelUserFields.createdatetime}`]: "createdatetime",
|
|
39
|
+
[`creator.${models_1.ModelUserFields.login_username}`]: "createusername",
|
|
40
|
+
[`usr.${models_1.ModelUserFields.updatedatetime}`]: "updatedatetime",
|
|
41
|
+
[`updater.${models_1.ModelUserFields.login_username}`]: "updateusername",
|
|
42
|
+
[`usr.${models_1.ModelUserFields.isdelete}`]: "isdelete",
|
|
43
|
+
[`usr.${models_1.ModelUserFields.istrash}`]: "istrash",
|
|
44
|
+
[`usr.${models_1.ModelUserFields.accountid}`]: "accountid",
|
|
45
|
+
};
|
|
25
46
|
const getCreatePayload = async (userType, data) => {
|
|
26
47
|
if ("user" in data) {
|
|
27
48
|
// have to hash the password
|
|
@@ -354,8 +375,22 @@ const UserService = (props) => {
|
|
|
354
375
|
}
|
|
355
376
|
return response;
|
|
356
377
|
};
|
|
357
|
-
const getUser = async ({ id, datatypes = [], includePassword = false, overrideUserType = "", skipFilterAccountId = false }) => {
|
|
378
|
+
const getUser = async ({ id, datatypes = [], includePassword = false, overrideUserType = "", skipFilterAccountId = false, skipFilterUserType = false }) => {
|
|
358
379
|
let data = {};
|
|
380
|
+
if (skipFilterUserType === true) {
|
|
381
|
+
let { data } = await listUsers({
|
|
382
|
+
includePassword,
|
|
383
|
+
limit: 1,
|
|
384
|
+
offset: 0,
|
|
385
|
+
filters: [{ field: "user_id", operator: "=", value: id }],
|
|
386
|
+
sortfield: "user_id",
|
|
387
|
+
sortorder: "ASC",
|
|
388
|
+
datatypes,
|
|
389
|
+
skipFilterAccountId,
|
|
390
|
+
skipFilterUserType
|
|
391
|
+
});
|
|
392
|
+
return data[0] ?? null;
|
|
393
|
+
}
|
|
359
394
|
const _userType = overrideUserType ? overrideUserType : userType;
|
|
360
395
|
if (_userType === "customer") {
|
|
361
396
|
data = await customerService.getCustomer({ id, datatypes: datatypes, includePassword });
|
|
@@ -383,9 +418,57 @@ const UserService = (props) => {
|
|
|
383
418
|
}
|
|
384
419
|
return data;
|
|
385
420
|
};
|
|
386
|
-
const listUsers = async ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword = false }) => {
|
|
421
|
+
const listUsers = async ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword = false, skipFilterAccountId = false, skipFilterUserType = false }) => {
|
|
387
422
|
let data = [];
|
|
388
423
|
let total = 0;
|
|
424
|
+
if (skipFilterUserType === true) {
|
|
425
|
+
mainSqlSelect = {
|
|
426
|
+
...mainSqlSelect,
|
|
427
|
+
...(includePassword ? { [`usr.${models_1.ModelUserFields.login_password}`]: "password" } : {}),
|
|
428
|
+
};
|
|
429
|
+
let sqlSelect = [
|
|
430
|
+
`COUNT(usr.*) OVER() as filtered_count`,
|
|
431
|
+
(0, lib_1.buildSqlSelect)(``, mainSqlSelect),
|
|
432
|
+
(0, lib_1.buildSqlSelect)(``, defaultSqlSelect)
|
|
433
|
+
];
|
|
434
|
+
let sqlRelation = [
|
|
435
|
+
(0, lib_1.buildSqlRelation)("left", "usr", "users", "creator", ["usr.createuserid = creator.user_id", "creator.isdelete = false", "creator.istrash = false"]),
|
|
436
|
+
(0, lib_1.buildSqlRelation)("left", "usr", "users", "updater", ["usr.updateuserid = updater.user_id", "updater.isdelete = false", "updater.istrash = false"])
|
|
437
|
+
];
|
|
438
|
+
let sqlGroupBy = [
|
|
439
|
+
...Object.keys(mainSqlSelect),
|
|
440
|
+
...Object.keys(defaultSqlSelect)
|
|
441
|
+
];
|
|
442
|
+
let filterColumns = {
|
|
443
|
+
...mainSqlSelect,
|
|
444
|
+
...defaultSqlSelect
|
|
445
|
+
};
|
|
446
|
+
let sqlWhere = [
|
|
447
|
+
`usr.isdelete = false`,
|
|
448
|
+
`usr.istrash = false`,
|
|
449
|
+
...(filters.length ? [(0, lib_1.buildSqlWhere)(filters, filterColumns)?.where] : []),
|
|
450
|
+
];
|
|
451
|
+
let sqlOrderby = (0, lib_1.buildSqlOrderBy)(sortfield, sortorder);
|
|
452
|
+
let sqlLimitOffset = (0, lib_1.buildSqlLimitOffset)(limit, offset);
|
|
453
|
+
const sqlRaw = (0, lib_1.buildSqlRawSelect)({
|
|
454
|
+
tableName: "users",
|
|
455
|
+
mainAlias: "usr",
|
|
456
|
+
accountId: rest.accountId,
|
|
457
|
+
sqlSelect,
|
|
458
|
+
sqlRelation,
|
|
459
|
+
sqlWhere,
|
|
460
|
+
sqlGroupBy,
|
|
461
|
+
sqlOrderby,
|
|
462
|
+
sqlLimitOffset,
|
|
463
|
+
skipFilterAccountId
|
|
464
|
+
});
|
|
465
|
+
data = await userModel.raw(sqlRaw);
|
|
466
|
+
const response = {
|
|
467
|
+
data: data.map(({ filtered_count, ...rest }) => rest),
|
|
468
|
+
total: data.length ? Number(data[0].filtered_count) : 0
|
|
469
|
+
};
|
|
470
|
+
return response;
|
|
471
|
+
}
|
|
389
472
|
if (userType === "customer") {
|
|
390
473
|
({ data, total } = await customerService.listCustomers({ includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes }));
|
|
391
474
|
}
|
|
@@ -393,7 +476,7 @@ const UserService = (props) => {
|
|
|
393
476
|
({ data, total } = await operatorService.listOperators({ includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes }));
|
|
394
477
|
}
|
|
395
478
|
if (userType === "administrator") {
|
|
396
|
-
({ data, total } = await administratorService.listAdministrators({ includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes }));
|
|
479
|
+
({ data, total } = await administratorService.listAdministrators({ includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes, skipFilterAccountId }));
|
|
397
480
|
}
|
|
398
481
|
if (userType === "worker") {
|
|
399
482
|
({ data, total } = await workerService.listWorkers({ includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../../src/services/user/UserService.ts"],"names":[],"mappings":";;;AAAA,qCAIkB;AAElB,uDAA0E;AAC1E,uDAAmI;AACnI,iEAAiK;AACjK,mDAAuH;AACvH,mDAAuH;AACvH,uDAAmI;AACnI,mDAAuH;AAIvH,mCAA0D;AAE1D,mCAAuC;AACvC,uDAAmI;AAEtH,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;CACV,CAAA;AAyJV,MAAM,gBAAgB,GAAG,KAAK,EAAE,QAAkB,EAAE,IAA6B,EAAE,EAAE;IAEjF,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QAEjB,4BAA4B;QAE5B,OAAO;YACH,CAAC,GAAG,wBAAe,CAAC,cAAc,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa;YAC9D,CAAC,GAAG,wBAAe,CAAC,cAAc,EAAE,CAAC,EAAE,MAAM,IAAA,oBAAY,EAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;YAClF,CAAC,GAAG,wBAAe,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YACjD,CAAC,GA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,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;YAC1B,IAAI,GAAG,eAAe,CAAC,YAAY,EAAE,CAAA;QACzC,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC,CAAC;IAEF,OAAO;QACH,UAAU;QACV,UAAU;QACV,OAAO;QACP,SAAS;QACT,WAAW;QACX,eAAe;QACf,gBAAgB;KACnB,CAAA;AAEL,CAAC,CAAA;AApnBY,QAAA,WAAW,eAonBvB","sourcesContent":["import {\n UserModel,\n ModelUserFields,\n ModelAdministratorFields\n} from \"@/models\";\n\nimport { UserPropService, UserPropReplaceProps } from \"./UserPropService\";\nimport { CustomerGetProps, CustomerCreateProps, CustomerListProps, CustomerUpdateProps, CustomerService } from \"./CustomerService\";\nimport { AdministratorGetProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorListProps, AdministratorService } from \"./AdministratorService\";\nimport { WorkerCreateProps, WorkerGetProps, WorkerUpdateProps, WorkerListProps, WorkerService } from \"./WorkerService\";\nimport { DriverCreateProps, DriverGetProps, DriverUpdateProps, DriverListProps, DriverService } from \"./DriverService\";\nimport { RetailerCreateProps, RetailerGetProps, RetailerUpdateProps, RetailerListProps, RetailerService } from \"./RetailerService\";\nimport { MemberCreateProps, MemberGetProps, MemberUpdateProps, MemberListProps, MemberService } from \"./MemberService\";\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n\nimport { DefaultServiceProps, throwError } from \"@/utils\";\n\nimport { hashPassword } from \"@/utils\";\nimport { OperatorCreateProps, OperatorGetProps, OperatorListProps, OperatorService, OperatorUpdateProps } from \"./OperatorService\";\n\nexport const userTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n supplier: \"supplier\",\n customer: \"customer\",\n driver: \"driver\",\n retailer: \"retailer\",\n member: \"member\",\n} as const\n\nexport type UserType = typeof userTypes[keyof typeof userTypes]\n\nexport type UserServiceProps = DefaultServiceProps & {\n userType: UserType\n};\n\nexport type UserGetProps = QueryGet & {\n id: number,\n overrideUserType?: UserType | \"\"\n includePassword?: boolean,\n skipFilterAccountId?: boolean\n};\n\nexport type UserListProps = QueryList & {\n // id: number,\n includePassword?: boolean\n};\n\nexport type UserRemoveProps = {\n ids: BigInt[]\n};\n\nexport type UserCreateProps = {\n userType?: UserType,\n data: {\n user: {\n loginUsername: string\n loginPassword: string\n address: string\n contact: string\n email: string\n firstname: string\n lastname: string\n status: boolean\n }\n } & (\n // operator\n {\n operator: Omit<OperatorCreateProps[\"data\"][\"operator\"], \"userId\">,\n } |\n // customer\n {\n customer: Omit<CustomerCreateProps[\"data\"][\"customer\"], \"userId\">,\n } |\n // administrator\n {\n administrator: Omit<AdministratorCreateProps[\"data\"][\"administrator\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // worker\n {\n worker: Omit<WorkerCreateProps[\"data\"][\"worker\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // driver\n {\n driver: Omit<DriverCreateProps[\"data\"][\"driver\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // member\n {\n member: Omit<MemberCreateProps[\"data\"][\"member\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n } |\n // retailer\n {\n retailer: Omit<RetailerCreateProps[\"data\"][\"retailer\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n }\n )\n}\n\nexport type UserUpdateProps = {\n id: number,\n userType?: UserType,\n data: {\n user: {\n loginUsername: string\n loginPassword?: string\n address: string\n contact: string\n email: string\n firstname: string\n lastname: string\n status: boolean\n }\n } & (\n // operator\n {\n operator: Omit<OperatorUpdateProps[\"data\"][\"operator\"], \"userId\">\n } |\n // customer\n {\n customer: Omit<CustomerUpdateProps[\"data\"][\"customer\"], \"userId\">\n } |\n // administrator\n {\n administrator: Omit<AdministratorUpdateProps[\"data\"][\"administrator\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // worker\n {\n worker: Omit<WorkerUpdateProps[\"data\"][\"worker\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // driver\n {\n driver: Omit<DriverUpdateProps[\"data\"][\"driver\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // member\n {\n member: Omit<MemberUpdateProps[\"data\"][\"member\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n } |\n // retailer\n {\n retailer: Omit<RetailerUpdateProps[\"data\"][\"retailer\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n }\n )\n}\n\nexport type UserReplacePasswordProps = {\n id: number,\n data: {\n unhashLoginPassword: string\n },\n isOperator: boolean\n}\n\nconst getCreatePayload = async (userType: UserType, data: UserCreateProps[\"data\"]) => {\n\n if (\"user\" in data) {\n\n // have to hash the password\n\n return {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.login_password}`]: await hashPassword(data.user.loginPassword),\n [`${ModelUserFields.address}`]: data.user.address,\n [`${ModelUserFields.contact}`]: data.user.contact,\n [`${ModelUserFields.email}`]: data.user.email,\n [`${ModelUserFields.firstname}`]: data.user.firstname,\n [`${ModelUserFields.lastname}`]: data.user.lastname,\n [`${ModelUserFields.status}`]: data.user.status ? 1 : 0,\n [`${ModelUserFields.user_type}`]: `${userType}`\n }\n }\n\n return false\n\n}\n\nconst getUpdatePayload = (userType: UserType, data: UserUpdateProps[\"data\"]) => {\n\n if (\"user\" in data) {\n\n return {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n ...(data?.user?.loginPassword ? { [`${ModelUserFields.login_password}`]: data.user.loginPassword } : {}),\n [`${ModelUserFields.address}`]: data.user.address,\n [`${ModelUserFields.contact}`]: data.user.contact,\n [`${ModelUserFields.email}`]: data.user.email,\n [`${ModelUserFields.firstname}`]: data.user.firstname,\n [`${ModelUserFields.lastname}`]: data.user.lastname,\n [`${ModelUserFields.status}`]: data.user.status ? 1 : 0,\n [`${ModelUserFields.user_type}`]: `${userType}`\n }\n }\n\n return false\n\n}\n\nexport const UserService = (props: UserServiceProps) => {\n\n const {\n // prisma,\n userType = \"administrator\",\n ...rest\n // accountId = 0,\n // actionUserId = 0,\n } = props\n\n const userModel = UserModel({ ...rest })\n\n const userPropService = UserPropService({ ...rest, userPropType: \"LOCATION_ID\" })\n const customerService = CustomerService({ ...rest })\n const administratorService = AdministratorService({ ...rest })\n const operatorService = OperatorService({ ...rest })\n const workerService = WorkerService({ ...rest })\n const driverService = DriverService({ ...rest })\n const retailerService = RetailerService({ ...rest })\n const memberService = MemberService({ ...rest })\n\n const createUser = async ({ data, userType: overrideUserType }: UserCreateProps) => {\n\n const _userType = overrideUserType || userType\n\n // check the username duplicated?\n const checkUsername = await userModel.list({\n limit: 1,\n offset: 0,\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: [],\n where: {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.accountid}`]: Number(rest.accountId),\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false\n },\n })\n\n // console.log('ch', checkUsername)\n\n if (checkUsername.length > 0) throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n\n const _data = await getCreatePayload(_userType, data)\n\n if (!_data) {\n throw new Error(`Invalid create payload: ${JSON.stringify(_data)}`);\n }\n\n // create user\n let responseUser = await userModel.create({ data: _data })\n\n let newUserId = responseUser.user_id\n\n let response: any = {}\n\n if (_userType === \"customer\" && \"customer\" in data) {\n\n let dataCustomer: CustomerCreateProps[\"data\"] = {\n customer: {\n ...data.customer,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create customer\n await customerService.createCustomer({ data: dataCustomer })\n\n response = await customerService.getCustomer({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"administrator\" && \"administrator\" in data) {\n\n let dataAdministrator: AdministratorCreateProps[\"data\"] = {\n administrator: {\n ...data.administrator,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create administrator\n await administratorService.createAdministrator({ data: dataAdministrator })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await administratorService.getAdministrator({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"operator\" && \"operator\" in data) {\n\n let dataOperator: OperatorCreateProps[\"data\"] = {\n operator: {\n ...data.operator,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create operator\n await operatorService.createOperator({ data: dataOperator })\n\n response = await operatorService.getOperator({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"worker\" && \"worker\" in data) {\n\n let dataWorker: WorkerCreateProps[\"data\"] = {\n worker: {\n ...data.worker,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create worker\n await workerService.createWorker({ data: dataWorker })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await workerService.getWorker({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"driver\" && \"driver\" in data) {\n\n let dataDriver: DriverCreateProps[\"data\"] = {\n driver: {\n ...data.driver,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create driver\n await driverService.createDriver({ data: dataDriver })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await driverService.getDriver({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"member\" && \"member\" in data) {\n\n let dataMember: MemberCreateProps[\"data\"] = {\n member: {\n ...data.member,\n // userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create member\n await memberService.createMember({ userId: Number(newUserId), data: dataMember })\n\n // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(newUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n response = await memberService.getMember({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"retailer\" && \"retailer\" in data) {\n\n let dataRetailer: RetailerCreateProps[\"data\"] = {\n retailer: {\n ...data.retailer,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create retailer\n await retailerService.createRetailer({ data: dataRetailer })\n\n response = await retailerService.getRetailer({ id: Number(newUserId), datatypes: [] })\n }\n\n return response\n }\n\n const updateUser = async ({ id, data, userType: overrideUserType }: UserUpdateProps) => {\n\n const _userType = overrideUserType || userType\n\n // check the username duplicated?\n const checkUsername = await userModel.list({\n limit: 1,\n offset: 0,\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: [],\n where: {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false,\n [`${ModelUserFields.accountid}`]: rest.accountId,\n },\n })\n\n // console.log('ch', checkUsername)\n\n if (checkUsername.length > 0) {\n if (Number(checkUsername[0]?.user_id) !== Number(id)) { // if not self user id\n throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n }\n }\n\n const _data = getUpdatePayload(_userType, data)\n\n if (!_data) {\n throw new Error(`Invalid update payload: ${JSON.stringify(_data)}`);\n }\n\n // update user\n let responseUser = await userModel.update({ id, data: _data })\n\n let updateUserId = responseUser.user_id\n\n let response: any = {}\n\n if (_userType === \"customer\" && \"customer\" in data) {\n\n let dataCustomer: CustomerUpdateProps[\"data\"] = {\n customer: {\n ...data.customer\n }\n }\n\n await customerService.updateCustomer({ userId: Number(updateUserId), data: dataCustomer })\n\n response = await customerService.getCustomer({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"operator\" && \"operator\" in data) {\n\n let dataOperator: OperatorUpdateProps[\"data\"] = {\n operator: {\n ...data.operator\n }\n }\n\n await operatorService.updateOperator({ userId: Number(updateUserId), data: dataOperator })\n\n response = await operatorService.getOperator({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"administrator\" && \"administrator\" in data) {\n\n let dataCustomer: AdministratorUpdateProps[\"data\"] = {\n administrator: {\n ...data.administrator\n }\n }\n\n await administratorService.updateAdministrator({ userId: Number(updateUserId), data: dataCustomer })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await administratorService.getAdministrator({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"worker\" && \"worker\" in data) {\n\n let dataWorker: WorkerUpdateProps[\"data\"] = {\n worker: {\n ...data.worker\n }\n }\n\n await workerService.updateWorker({ userId: Number(updateUserId), data: dataWorker })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await workerService.getWorker({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"driver\" && \"driver\" in data) {\n\n let dataDriver: DriverUpdateProps[\"data\"] = {\n driver: {\n ...data.driver\n }\n }\n\n await driverService.updateDriver({ userId: Number(updateUserId), data: dataDriver })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await driverService.getDriver({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"member\" && \"member\" in data) {\n\n let dataMember: MemberUpdateProps[\"data\"] = {\n member: {\n ...data.member\n }\n }\n\n await memberService.updateMember({ userId: Number(updateUserId), data: dataMember })\n\n // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n response = await memberService.getMember({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"retailer\" && \"retailer\" in data) {\n\n let dataRetailer: RetailerUpdateProps[\"data\"] = {\n retailer: {\n ...data.retailer\n }\n }\n\n await retailerService.updateRetailer({ userId: Number(updateUserId), data: dataRetailer })\n\n response = await retailerService.getRetailer({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n return response\n }\n\n const getUser = async ({ id, datatypes = [], includePassword = false, overrideUserType = \"\", skipFilterAccountId = false }: UserGetProps) => {\n\n let data: any = {}\n\n const _userType = overrideUserType ? overrideUserType : userType\n\n if (_userType === \"customer\") {\n data = await customerService.getCustomer({ id, datatypes: datatypes as CustomerGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"operator\") {\n data = await operatorService.getOperator({ id, datatypes: datatypes as OperatorGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"administrator\") {\n data = await administratorService.getAdministrator({ id, datatypes: datatypes as AdministratorGetProps[\"datatypes\"], includePassword, skipFilterAccountId })\n }\n\n if (_userType === \"worker\") {\n data = await workerService.getWorker({ id, datatypes: datatypes as WorkerGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"driver\") {\n data = await driverService.getDriver({ id, datatypes: datatypes as DriverGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"member\") {\n data = await memberService.getMember({ id, datatypes: datatypes as MemberGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"retailer\") {\n data = await retailerService.getRetailer({ id, datatypes: datatypes as RetailerGetProps[\"datatypes\"], includePassword })\n }\n\n if (!data) {\n throw new Error(`Invalid id: ${id}`);\n }\n\n return data\n };\n\n const listUsers = async ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword = false }: UserListProps) => {\n\n let data: any[] = [];\n let total = 0;\n\n if (userType === \"customer\") {\n ({ data, total } = await customerService.listCustomers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as CustomerListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"operator\") {\n ({ data, total } = await operatorService.listOperators(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as OperatorListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"administrator\") {\n ({ data, total } = await administratorService.listAdministrators(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as AdministratorListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"worker\") {\n ({ data, total } = await workerService.listWorkers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as WorkerListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"driver\") {\n ({ data, total } = await driverService.listDrivers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as DriverListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"member\") {\n ({ data, total } = await memberService.listMembers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as MemberListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"retailer\") {\n ({ data, total } = await retailerService.listRetailers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as RetailerListProps[\"datatypes\"] }\n ))\n }\n\n return {\n data,\n total\n }\n };\n\n const removeUsers = async ({ ids }: UserRemoveProps) => {\n\n if (!ids.length) throwError('id is required');\n\n let response: any[] = []\n\n if (userType === \"customer\") {\n response = await customerService.removeCustomers({ userIds: ids })\n }\n\n if (userType === \"operator\") {\n response = await operatorService.removeOperators({ userIds: ids })\n }\n\n if (userType === \"administrator\") {\n\n // have to check the ids is is_owner account\n const { data: administrators } = await administratorService.listAdministrators({\n limit: 9999,\n offset: 0,\n filters: [{\n field: `${ModelAdministratorFields.user_id}`,\n operator: \"where_in\",\n value: ids\n }],\n sortfield: `${ModelAdministratorFields.administrator_id}`,\n sortorder: \"ASC\",\n datatypes: []\n })\n\n const ownerAdministrators = administrators.filter(i => i.is_owner === true)\n\n if (ownerAdministrators.length > 0) {\n throw new Error(`Cannot delete on administrator owner user ids: ${ownerAdministrators.map(i => i.user_id)}`);\n }\n\n response = await administratorService.removeAdministrators({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"worker\") {\n response = await workerService.removeWorkers({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"driver\") {\n response = await driverService.removeDrivers({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"member\") {\n response = await memberService.removeMembers({ userIds: ids })\n // await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"retailer\") {\n response = await retailerService.removeRetailers({ userIds: ids })\n // await userPropService.removeUserProps({ userIds: ids })\n }\n\n // remove user\n let responseUser = await userModel.remove({ ids: ids.map(i => Number(i)) })\n\n response.forEach((i, index) => {\n i.user = responseUser[index]\n })\n\n return response\n };\n\n const replacePassword = async ({ id, data, isOperator = false }: UserReplacePasswordProps) => {\n\n const passwordUserModel = UserModel({\n ...rest,\n ...(isOperator === true ? { isOperator } : {})\n })\n\n // update user password\n let responseUser = await passwordUserModel.update({\n id,\n data: {\n login_password: await hashPassword(data?.unhashLoginPassword)\n }\n })\n\n let updateUserId = responseUser.user_id\n\n let response = await getUser({ id: Number(updateUserId), includePassword: false, datatypes: [] })\n\n return response\n }\n\n const getUserDataTypes = () => {\n\n let data: any[] = [];\n let total = 0;\n\n if (userType === \"customer\") {\n data = customerService.getDataTypes()\n }\n\n if (userType === \"operator\") {\n data = operatorService.getDataTypes()\n }\n\n if (userType === \"administrator\") {\n data = administratorService.getDataTypes()\n }\n\n if (userType === \"worker\") {\n data = workerService.getDataTypes()\n }\n\n if (userType === \"driver\") {\n data = driverService.getDataTypes()\n }\n\n if (userType === \"member\") {\n data = memberService.getDataTypes()\n }\n\n if (userType === \"retailer\") {\n data = retailerService.getDataTypes()\n }\n\n return data\n };\n\n return {\n createUser,\n updateUser,\n getUser,\n listUsers,\n removeUsers,\n replacePassword,\n getUserDataTypes\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../../src/services/user/UserService.ts"],"names":[],"mappings":";;;AAAA,qCAIkB;AAElB,uDAA0E;AAC1E,uDAAmI;AACnI,iEAAiK;AACjK,mDAAuH;AACvH,mDAAuH;AACvH,uDAAmI;AACnI,mDAAuH;AAGvH,+BAAgK;AAEhK,mCAA0D;AAE1D,mCAAuC;AACvC,uDAAmI;AAEtH,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;CACV,CAAA;AA4JV,IAAI,aAAa,GAAG;IAChB,CAAC,OAAO,wBAAe,CAAC,OAAO,EAAE,CAAC,EAAE,SAAS;IAC7C,CAAC,OAAO,wBAAe,CAAC,S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AAA;QACzC,CAAC;QAED,IAAI,QAAQ,KAAK,eAAe,EAAE,CAAC;YAC/B,IAAI,GAAG,oBAAoB,CAAC,YAAY,EAAE,CAAA;QAC9C,CAAC;QAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,GAAG,aAAa,CAAC,YAAY,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;YAC1B,IAAI,GAAG,eAAe,CAAC,YAAY,EAAE,CAAA;QACzC,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC,CAAC;IAEF,OAAO;QACH,UAAU;QACV,UAAU;QACV,OAAO;QACP,SAAS;QACT,WAAW;QACX,eAAe;QACf,gBAAgB;KACnB,CAAA;AAEL,CAAC,CAAA;AAjsBY,QAAA,WAAW,eAisBvB","sourcesContent":["import {\n UserModel,\n ModelUserFields,\n ModelAdministratorFields\n} from \"@/models\";\n\nimport { UserPropService, UserPropReplaceProps } from \"./UserPropService\";\nimport { CustomerGetProps, CustomerCreateProps, CustomerListProps, CustomerUpdateProps, CustomerService } from \"./CustomerService\";\nimport { AdministratorGetProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorListProps, AdministratorService } from \"./AdministratorService\";\nimport { WorkerCreateProps, WorkerGetProps, WorkerUpdateProps, WorkerListProps, WorkerService } from \"./WorkerService\";\nimport { DriverCreateProps, DriverGetProps, DriverUpdateProps, DriverListProps, DriverService } from \"./DriverService\";\nimport { RetailerCreateProps, RetailerGetProps, RetailerUpdateProps, RetailerListProps, RetailerService } from \"./RetailerService\";\nimport { MemberCreateProps, MemberGetProps, MemberUpdateProps, MemberListProps, MemberService } from \"./MemberService\";\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\nimport { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect } from \"@/lib\";\n\nimport { DefaultServiceProps, throwError } from \"@/utils\";\n\nimport { hashPassword } from \"@/utils\";\nimport { OperatorCreateProps, OperatorGetProps, OperatorListProps, OperatorService, OperatorUpdateProps } from \"./OperatorService\";\n\nexport const userTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n supplier: \"supplier\",\n customer: \"customer\",\n driver: \"driver\",\n retailer: \"retailer\",\n member: \"member\",\n} as const\n\nexport type UserType = typeof userTypes[keyof typeof userTypes]\n\nexport type UserServiceProps = DefaultServiceProps & {\n userType: UserType\n};\n\nexport type UserGetProps = QueryGet & {\n id: number,\n overrideUserType?: UserType | \"\"\n includePassword?: boolean,\n skipFilterAccountId?: boolean\n skipFilterUserType?: boolean\n};\n\nexport type UserListProps = QueryList & {\n // id: number,\n includePassword?: boolean\n skipFilterAccountId?: boolean\n skipFilterUserType?: boolean\n};\n\nexport type UserRemoveProps = {\n ids: BigInt[]\n};\n\nexport type UserCreateProps = {\n userType?: UserType,\n data: {\n user: {\n loginUsername: string\n loginPassword: string\n address: string\n contact: string\n email: string\n firstname: string\n lastname: string\n status: boolean\n }\n } & (\n // operator\n {\n operator: Omit<OperatorCreateProps[\"data\"][\"operator\"], \"userId\">,\n } |\n // customer\n {\n customer: Omit<CustomerCreateProps[\"data\"][\"customer\"], \"userId\">,\n } |\n // administrator\n {\n administrator: Omit<AdministratorCreateProps[\"data\"][\"administrator\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // worker\n {\n worker: Omit<WorkerCreateProps[\"data\"][\"worker\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // driver\n {\n driver: Omit<DriverCreateProps[\"data\"][\"driver\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // member\n {\n member: Omit<MemberCreateProps[\"data\"][\"member\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n } |\n // retailer\n {\n retailer: Omit<RetailerCreateProps[\"data\"][\"retailer\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n }\n )\n}\n\nexport type UserUpdateProps = {\n id: number,\n userType?: UserType,\n data: {\n user: {\n loginUsername: string\n loginPassword?: string\n address: string\n contact: string\n email: string\n firstname: string\n lastname: string\n status: boolean\n }\n } & (\n // operator\n {\n operator: Omit<OperatorUpdateProps[\"data\"][\"operator\"], \"userId\">\n } |\n // customer\n {\n customer: Omit<CustomerUpdateProps[\"data\"][\"customer\"], \"userId\">\n } |\n // administrator\n {\n administrator: Omit<AdministratorUpdateProps[\"data\"][\"administrator\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // worker\n {\n worker: Omit<WorkerUpdateProps[\"data\"][\"worker\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // driver\n {\n driver: Omit<DriverUpdateProps[\"data\"][\"driver\"], \"userId\">\n props: {\n locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n }\n } |\n // member\n {\n member: Omit<MemberUpdateProps[\"data\"][\"member\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n } |\n // retailer\n {\n retailer: Omit<RetailerUpdateProps[\"data\"][\"retailer\"], \"userId\">\n // props: {\n // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n // }\n }\n )\n}\n\nexport type UserReplacePasswordProps = {\n id: number,\n data: {\n unhashLoginPassword: string\n },\n isOperator: boolean\n}\n\nlet mainSqlSelect = {\n [`usr.${ModelUserFields.user_id}`]: \"user_id\",\n [`usr.${ModelUserFields.user_type}`]: \"user_type\",\n [`usr.${ModelUserFields.login_username}`]: \"username\",\n [`usr.${ModelUserFields.firstname}`]: \"firstname\",\n [`usr.${ModelUserFields.lastname}`]: \"lastname\",\n [`usr.${ModelUserFields.contact}`]: \"contact\",\n [`usr.${ModelUserFields.email}`]: \"email\",\n [`usr.${ModelUserFields.address}`]: \"address\",\n [`usr.${ModelUserFields.status}`]: \"status\",\n}\n\nlet defaultSqlSelect = {\n [`usr.${ModelUserFields.createdatetime}`]: \"createdatetime\",\n [`creator.${ModelUserFields.login_username}`]: \"createusername\",\n [`usr.${ModelUserFields.updatedatetime}`]: \"updatedatetime\",\n [`updater.${ModelUserFields.login_username}`]: \"updateusername\",\n [`usr.${ModelUserFields.isdelete}`]: \"isdelete\",\n [`usr.${ModelUserFields.istrash}`]: \"istrash\",\n [`usr.${ModelUserFields.accountid}`]: \"accountid\",\n}\n\nconst getCreatePayload = async (userType: UserType, data: UserCreateProps[\"data\"]) => {\n\n if (\"user\" in data) {\n\n // have to hash the password\n\n return {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.login_password}`]: await hashPassword(data.user.loginPassword),\n [`${ModelUserFields.address}`]: data.user.address,\n [`${ModelUserFields.contact}`]: data.user.contact,\n [`${ModelUserFields.email}`]: data.user.email,\n [`${ModelUserFields.firstname}`]: data.user.firstname,\n [`${ModelUserFields.lastname}`]: data.user.lastname,\n [`${ModelUserFields.status}`]: data.user.status ? 1 : 0,\n [`${ModelUserFields.user_type}`]: `${userType}`\n }\n }\n\n return false\n\n}\n\nconst getUpdatePayload = (userType: UserType, data: UserUpdateProps[\"data\"]) => {\n\n if (\"user\" in data) {\n\n return {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n ...(data?.user?.loginPassword ? { [`${ModelUserFields.login_password}`]: data.user.loginPassword } : {}),\n [`${ModelUserFields.address}`]: data.user.address,\n [`${ModelUserFields.contact}`]: data.user.contact,\n [`${ModelUserFields.email}`]: data.user.email,\n [`${ModelUserFields.firstname}`]: data.user.firstname,\n [`${ModelUserFields.lastname}`]: data.user.lastname,\n [`${ModelUserFields.status}`]: data.user.status ? 1 : 0,\n [`${ModelUserFields.user_type}`]: `${userType}`\n }\n }\n\n return false\n\n}\n\nexport const UserService = (props: UserServiceProps) => {\n\n const {\n // prisma,\n userType = \"administrator\",\n ...rest\n // accountId = 0,\n // actionUserId = 0,\n } = props\n\n const userModel = UserModel({ ...rest })\n\n const userPropService = UserPropService({ ...rest, userPropType: \"LOCATION_ID\" })\n const customerService = CustomerService({ ...rest })\n const administratorService = AdministratorService({ ...rest })\n const operatorService = OperatorService({ ...rest })\n const workerService = WorkerService({ ...rest })\n const driverService = DriverService({ ...rest })\n const retailerService = RetailerService({ ...rest })\n const memberService = MemberService({ ...rest })\n\n const createUser = async ({ data, userType: overrideUserType }: UserCreateProps) => {\n\n const _userType = overrideUserType || userType\n\n // check the username duplicated?\n const checkUsername = await userModel.list({\n limit: 1,\n offset: 0,\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: [],\n where: {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.accountid}`]: Number(rest.accountId),\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false\n },\n })\n\n // console.log('ch', checkUsername)\n\n if (checkUsername.length > 0) throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n\n const _data = await getCreatePayload(_userType, data)\n\n if (!_data) {\n throw new Error(`Invalid create payload: ${JSON.stringify(_data)}`);\n }\n\n // create user\n let responseUser = await userModel.create({ data: _data })\n\n let newUserId = responseUser.user_id\n\n let response: any = {}\n\n if (_userType === \"customer\" && \"customer\" in data) {\n\n let dataCustomer: CustomerCreateProps[\"data\"] = {\n customer: {\n ...data.customer,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create customer\n await customerService.createCustomer({ data: dataCustomer })\n\n response = await customerService.getCustomer({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"administrator\" && \"administrator\" in data) {\n\n let dataAdministrator: AdministratorCreateProps[\"data\"] = {\n administrator: {\n ...data.administrator,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create administrator\n await administratorService.createAdministrator({ data: dataAdministrator })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await administratorService.getAdministrator({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"operator\" && \"operator\" in data) {\n\n let dataOperator: OperatorCreateProps[\"data\"] = {\n operator: {\n ...data.operator,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create operator\n await operatorService.createOperator({ data: dataOperator })\n\n response = await operatorService.getOperator({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"worker\" && \"worker\" in data) {\n\n let dataWorker: WorkerCreateProps[\"data\"] = {\n worker: {\n ...data.worker,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create worker\n await workerService.createWorker({ data: dataWorker })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await workerService.getWorker({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"driver\" && \"driver\" in data) {\n\n let dataDriver: DriverCreateProps[\"data\"] = {\n driver: {\n ...data.driver,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create driver\n await driverService.createDriver({ data: dataDriver })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(newUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await driverService.getDriver({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"member\" && \"member\" in data) {\n\n let dataMember: MemberCreateProps[\"data\"] = {\n member: {\n ...data.member,\n // userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create member\n await memberService.createMember({ userId: Number(newUserId), data: dataMember })\n\n // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(newUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n response = await memberService.getMember({ id: Number(newUserId), datatypes: [] })\n }\n\n if (_userType === \"retailer\" && \"retailer\" in data) {\n\n let dataRetailer: RetailerCreateProps[\"data\"] = {\n retailer: {\n ...data.retailer,\n userId: Number(newUserId) ?? \"\"\n }\n }\n\n // create retailer\n await retailerService.createRetailer({ data: dataRetailer })\n\n response = await retailerService.getRetailer({ id: Number(newUserId), datatypes: [] })\n }\n\n return response\n }\n\n const updateUser = async ({ id, data, userType: overrideUserType }: UserUpdateProps) => {\n\n const _userType = overrideUserType || userType\n\n // check the username duplicated?\n const checkUsername = await userModel.list({\n limit: 1,\n offset: 0,\n orderBy: {\n [`${ModelUserFields.user_id}`]: \"asc\"\n },\n include: [],\n where: {\n [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n [`${ModelUserFields.isdelete}`]: false,\n [`${ModelUserFields.istrash}`]: false,\n [`${ModelUserFields.accountid}`]: rest.accountId,\n },\n })\n\n // console.log('ch', checkUsername)\n\n if (checkUsername.length > 0) {\n if (Number(checkUsername[0]?.user_id) !== Number(id)) { // if not self user id\n throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n }\n }\n\n const _data = getUpdatePayload(_userType, data)\n\n if (!_data) {\n throw new Error(`Invalid update payload: ${JSON.stringify(_data)}`);\n }\n\n // update user\n let responseUser = await userModel.update({ id, data: _data })\n\n let updateUserId = responseUser.user_id\n\n let response: any = {}\n\n if (_userType === \"customer\" && \"customer\" in data) {\n\n let dataCustomer: CustomerUpdateProps[\"data\"] = {\n customer: {\n ...data.customer\n }\n }\n\n await customerService.updateCustomer({ userId: Number(updateUserId), data: dataCustomer })\n\n response = await customerService.getCustomer({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"operator\" && \"operator\" in data) {\n\n let dataOperator: OperatorUpdateProps[\"data\"] = {\n operator: {\n ...data.operator\n }\n }\n\n await operatorService.updateOperator({ userId: Number(updateUserId), data: dataOperator })\n\n response = await operatorService.getOperator({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"administrator\" && \"administrator\" in data) {\n\n let dataCustomer: AdministratorUpdateProps[\"data\"] = {\n administrator: {\n ...data.administrator\n }\n }\n\n await administratorService.updateAdministrator({ userId: Number(updateUserId), data: dataCustomer })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await administratorService.getAdministrator({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"worker\" && \"worker\" in data) {\n\n let dataWorker: WorkerUpdateProps[\"data\"] = {\n worker: {\n ...data.worker\n }\n }\n\n await workerService.updateWorker({ userId: Number(updateUserId), data: dataWorker })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await workerService.getWorker({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"driver\" && \"driver\" in data) {\n\n let dataDriver: DriverUpdateProps[\"data\"] = {\n driver: {\n ...data.driver\n }\n }\n\n await driverService.updateDriver({ userId: Number(updateUserId), data: dataDriver })\n\n // replace user prop\n await userPropService.replaceUserProp({\n userPropType: \"LOCATION_ID\",\n data: {\n userProp: {\n userId: Number(updateUserId),\n locationIds: data.props.locationIds\n }\n }\n })\n\n response = await driverService.getDriver({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"member\" && \"member\" in data) {\n\n let dataMember: MemberUpdateProps[\"data\"] = {\n member: {\n ...data.member\n }\n }\n\n await memberService.updateMember({ userId: Number(updateUserId), data: dataMember })\n\n // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n response = await memberService.getMember({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n if (_userType === \"retailer\" && \"retailer\" in data) {\n\n let dataRetailer: RetailerUpdateProps[\"data\"] = {\n retailer: {\n ...data.retailer\n }\n }\n\n await retailerService.updateRetailer({ userId: Number(updateUserId), data: dataRetailer })\n\n response = await retailerService.getRetailer({ id: Number(updateUserId), datatypes: [] })\n\n }\n\n return response\n }\n\n const getUser = async ({ id, datatypes = [], includePassword = false, overrideUserType = \"\", skipFilterAccountId = false, skipFilterUserType = false }: UserGetProps) => {\n\n let data: any = {}\n\n if (skipFilterUserType === true) {\n\n let { data } = await listUsers({\n includePassword,\n limit: 1,\n offset: 0,\n filters: [{ field: \"user_id\", operator: \"=\", value: id }],\n sortfield: \"user_id\",\n sortorder: \"ASC\",\n datatypes,\n skipFilterAccountId,\n skipFilterUserType\n })\n\n return data[0] ?? null;\n }\n\n const _userType = overrideUserType ? overrideUserType : userType\n\n if (_userType === \"customer\") {\n data = await customerService.getCustomer({ id, datatypes: datatypes as CustomerGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"operator\") {\n data = await operatorService.getOperator({ id, datatypes: datatypes as OperatorGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"administrator\") {\n data = await administratorService.getAdministrator({ id, datatypes: datatypes as AdministratorGetProps[\"datatypes\"], includePassword, skipFilterAccountId })\n }\n\n if (_userType === \"worker\") {\n data = await workerService.getWorker({ id, datatypes: datatypes as WorkerGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"driver\") {\n data = await driverService.getDriver({ id, datatypes: datatypes as DriverGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"member\") {\n data = await memberService.getMember({ id, datatypes: datatypes as MemberGetProps[\"datatypes\"], includePassword })\n }\n\n if (_userType === \"retailer\") {\n data = await retailerService.getRetailer({ id, datatypes: datatypes as RetailerGetProps[\"datatypes\"], includePassword })\n }\n\n if (!data) {\n throw new Error(`Invalid id: ${id}`);\n }\n\n return data\n };\n\n const listUsers = async ({ limit, offset, filters, sortfield, sortorder, datatypes, includePassword = false, skipFilterAccountId = false, skipFilterUserType = false }: UserListProps) => {\n\n let data: any[] = [];\n let total = 0;\n\n if (skipFilterUserType === true) {\n\n mainSqlSelect = {\n ...mainSqlSelect,\n ...(includePassword ? { [`usr.${ModelUserFields.login_password}`]: \"password\" } : {}),\n }\n\n let sqlSelect = [\n `COUNT(usr.*) OVER() as filtered_count`,\n buildSqlSelect(``, mainSqlSelect),\n buildSqlSelect(``, defaultSqlSelect)\n ]\n\n let sqlRelation = [\n buildSqlRelation(\"left\", \"usr\", \"users\", \"creator\", [\"usr.createuserid = creator.user_id\", \"creator.isdelete = false\", \"creator.istrash = false\"]),\n buildSqlRelation(\"left\", \"usr\", \"users\", \"updater\", [\"usr.updateuserid = updater.user_id\", \"updater.isdelete = false\", \"updater.istrash = false\"])\n ]\n\n let sqlGroupBy: string[] = [\n ...Object.keys(mainSqlSelect),\n ...Object.keys(defaultSqlSelect)\n ]\n\n let filterColumns = {\n ...mainSqlSelect,\n ...defaultSqlSelect\n }\n\n let sqlWhere = [\n `usr.isdelete = false`,\n `usr.istrash = false`,\n ...(filters.length ? [buildSqlWhere(filters, filterColumns)?.where] : []),\n ]\n\n let sqlOrderby = buildSqlOrderBy(sortfield, sortorder)\n let sqlLimitOffset = buildSqlLimitOffset(limit, offset)\n\n const sqlRaw = buildSqlRawSelect({\n tableName: \"users\",\n mainAlias: \"usr\",\n accountId: rest.accountId,\n sqlSelect,\n sqlRelation,\n sqlWhere,\n sqlGroupBy,\n sqlOrderby,\n sqlLimitOffset,\n skipFilterAccountId\n })\n\n data = await userModel.raw(sqlRaw)\n\n const response = {\n data: data.map(({ filtered_count, ...rest }) => rest),\n total: data.length ? Number(data[0].filtered_count) : 0\n }\n\n return response\n }\n\n if (userType === \"customer\") {\n ({ data, total } = await customerService.listCustomers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as CustomerListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"operator\") {\n ({ data, total } = await operatorService.listOperators(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as OperatorListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"administrator\") {\n ({ data, total } = await administratorService.listAdministrators(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as AdministratorListProps[\"datatypes\"], skipFilterAccountId }\n ))\n }\n\n if (userType === \"worker\") {\n ({ data, total } = await workerService.listWorkers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as WorkerListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"driver\") {\n ({ data, total } = await driverService.listDrivers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as DriverListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"member\") {\n ({ data, total } = await memberService.listMembers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as MemberListProps[\"datatypes\"] }\n ))\n }\n\n if (userType === \"retailer\") {\n ({ data, total } = await retailerService.listRetailers(\n { includePassword, limit, offset, filters, sortfield, sortorder, datatypes: datatypes as RetailerListProps[\"datatypes\"] }\n ))\n }\n\n return {\n data,\n total\n }\n };\n\n const removeUsers = async ({ ids }: UserRemoveProps) => {\n\n if (!ids.length) throwError('id is required');\n\n let response: any[] = []\n\n if (userType === \"customer\") {\n response = await customerService.removeCustomers({ userIds: ids })\n }\n\n if (userType === \"operator\") {\n response = await operatorService.removeOperators({ userIds: ids })\n }\n\n if (userType === \"administrator\") {\n\n // have to check the ids is is_owner account\n const { data: administrators } = await administratorService.listAdministrators({\n limit: 9999,\n offset: 0,\n filters: [{\n field: `${ModelAdministratorFields.user_id}`,\n operator: \"where_in\",\n value: ids\n }],\n sortfield: `${ModelAdministratorFields.administrator_id}`,\n sortorder: \"ASC\",\n datatypes: []\n })\n\n const ownerAdministrators = administrators.filter(i => i.is_owner === true)\n\n if (ownerAdministrators.length > 0) {\n throw new Error(`Cannot delete on administrator owner user ids: ${ownerAdministrators.map(i => i.user_id)}`);\n }\n\n response = await administratorService.removeAdministrators({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"worker\") {\n response = await workerService.removeWorkers({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"driver\") {\n response = await driverService.removeDrivers({ userIds: ids })\n await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"member\") {\n response = await memberService.removeMembers({ userIds: ids })\n // await userPropService.removeUserProps({ userIds: ids })\n }\n\n if (userType === \"retailer\") {\n response = await retailerService.removeRetailers({ userIds: ids })\n // await userPropService.removeUserProps({ userIds: ids })\n }\n\n // remove user\n let responseUser = await userModel.remove({ ids: ids.map(i => Number(i)) })\n\n response.forEach((i, index) => {\n i.user = responseUser[index]\n })\n\n return response\n };\n\n const replacePassword = async ({ id, data, isOperator = false }: UserReplacePasswordProps) => {\n\n const passwordUserModel = UserModel({\n ...rest,\n ...(isOperator === true ? { isOperator } : {})\n })\n\n // update user password\n let responseUser = await passwordUserModel.update({\n id,\n data: {\n login_password: await hashPassword(data?.unhashLoginPassword)\n }\n })\n\n let updateUserId = responseUser.user_id\n\n let response = await getUser({ id: Number(updateUserId), includePassword: false, datatypes: [] })\n\n return response\n }\n\n const getUserDataTypes = () => {\n\n let data: any[] = [];\n let total = 0;\n\n if (userType === \"customer\") {\n data = customerService.getDataTypes()\n }\n\n if (userType === \"operator\") {\n data = operatorService.getDataTypes()\n }\n\n if (userType === \"administrator\") {\n data = administratorService.getDataTypes()\n }\n\n if (userType === \"worker\") {\n data = workerService.getDataTypes()\n }\n\n if (userType === \"driver\") {\n data = driverService.getDataTypes()\n }\n\n if (userType === \"member\") {\n data = memberService.getDataTypes()\n }\n\n if (userType === \"retailer\") {\n data = retailerService.getDataTypes()\n }\n\n return data\n };\n\n return {\n createUser,\n updateUser,\n getUser,\n listUsers,\n removeUsers,\n replacePassword,\n getUserDataTypes\n }\n\n}\n\n"]}
|