arkos 1.3.4-canary.6 → 1.3.4-canary.7
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/README.md +1 -1
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +230 -184
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +333 -552
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +11 -13
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +1 -1
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +8 -8
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +1 -3
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/base/base.controller.js +230 -184
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.service.js +333 -552
- package/dist/esm/modules/base/base.service.js.map +1 -1
- package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +11 -13
- package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/esm/utils/cli/build.js +1 -1
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/index.js +8 -8
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/helpers/fs.helpers.js +1 -3
- package/dist/esm/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/types/modules/base/base.controller.d.ts +16 -0
- package/dist/types/modules/base/base.service.d.ts +17 -1
- package/package.json +3 -3
package/README.md
CHANG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ACL,CAAC,CACF;QAED,iBAAiB,EAAE,IAAA,qBAAU,EAC3B,KAAK,EAAE,GAAiB,EAAE,GAAkB,EAAE,EAAE;YAC9C,MAAM,WAAW,GAAG,IAAA,uBAAc,GAAE,CAAC;YACrC,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;YAE9C,IAAI,CAAC,YAAY;gBACf,MAAM,IAAI,mBAAQ,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;YAE1D,MAAM,WAAW,GAAG,6BAAiB;iBAClC,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;gBACxC,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;gBACnB,IAAI,WAAW,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS;oBACjD,OAAQ,UAAkB,EAAE,KAAK,CAAC;gBACpC,OAAO,UAAU,CAAC;YACpB,CAAC,CAAC,CAAC;YAEL,IAAI,CAAC,WAAW;gBACd,MAAM,IAAI,mBAAQ,CAChB,qCAAqC,YAAY,EAAE,EACnD,GAAG,CACJ,CAAC;YAEJ,GAAG,CAAC,IAAI,CAAC;gBACP,KAAK,EAAE,WAAW,CAAC,MAAM;gBACzB,OAAO,EAAE,WAAW,CAAC,MAAM;gBAC3B,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC,CACF;KACF,CAAC;AACJ,CAAC,CAAC;AAtaW,QAAA,qBAAqB,yBAsahC","sourcesContent":["import catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { CookieOptions } from \"express\";\nimport { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"../../types\";\nimport authService from \"./auth.service\";\nimport { BaseService } from \"../base/base.service\";\nimport { User } from \"../../types\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n createPrismaWhereClause,\n determineUsernameField,\n getNestedValue,\n MsDuration,\n toMs,\n} from \"./utils/helpers/auth.controller.helpers\";\nimport authActionService from \"./utils/services/auth-action.service\";\n\n/**\n * Default fields to exclude from user object when returning to client\n */\nexport const defaultExcludedUserFields = {\n password: false,\n};\n\n/**\n * Factory function to create authentication controller with configurable interceptors\n *\n * @param interceptors - Optional middleware functions to execute after controller actions\n * @returns An object containing all authentication controller methods\n */\nexport const authControllerFactory = async (interceptors: any = {}) => {\n const userService = new BaseService(\"user\");\n\n return {\n /**\n * Retrieves the current authenticated user's information\n */\n getMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.findOne(\n { id: req.user!.id },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterGetMe) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Updates the current authenticated user's information\n */\n updateMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n {},\n \"InvalidFieldPassword\"\n );\n\n const user = (await userService.updateOne(\n { id: req.user!.id },\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterUpdateMe) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Logs out the current user by invalidating their access token cookie\n */\n logout: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (interceptors?.afterLogout) {\n req.responseData = null;\n res.locals.data = null;\n req.responseStatus = 204;\n res.locals.status = 204;\n return next();\n }\n\n res.status(204).json();\n }\n ),\n\n /**\n * Authenticates a user using configurable username field and password\n * Username field can be specified in query parameter or config\n *\n * Supports nested fields and array queries (e.g., \"profile.nickname\", \"phones.some.number\")\n */\n login: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n // For the error message, we only care about the top-level field name\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\n\n const { password } = req.body;\n\n if (!usernameValue || !password)\n return next(\n new AppError(`Please provide both ${lastField} and password`, 400)\n );\n\n // Create appropriate where clause for the query\n let whereClause: Record<string, any>;\n\n if (usernameField?.includes?.(\".\")) {\n // For nested paths, we need to extract the actual value to search for\n const valueToFind = getNestedValue(req.body, usernameField);\n if (valueToFind === undefined) {\n return next(new AppError(`Invalid ${usernameField} provided`, 400));\n }\n whereClause = createPrismaWhereClause(usernameField, valueToFind);\n } else {\n // Simple field case\n whereClause = { [usernameField]: usernameValue };\n }\n\n // Use findFirst instead of findUnique for complex queries\n const user = (await userService.findOne(\n whereClause,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (\n !user ||\n !(await authService.isCorrectPassword(password, user.password))\n ) {\n return next(new AppError(`Incorrect ${lastField} or password`, 401));\n }\n\n const token = authService.signJwtToken(user.id!);\n\n const cookieOptions: CookieOptions = {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ||\n process.env.JWT_COOKIE_HTTP_ONLY === \"true\" ||\n true,\n secure:\n authConfigs?.jwt?.cookie?.secure ||\n process.env.JWT_COOKIE_SECURE === \"true\" ||\n req.secure ||\n req.headers[\"x-forwarded-proto\"] === \"https\",\n sameSite:\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n (process.env.NODE_ENV === \"production\" ? \"none\" : \"lax\"),\n };\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n req.responseData = { accessToken: token };\n res.locals.data = { accessToken: token };\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.cookie(\"arkos_access_token\", token, cookieOptions);\n\n req.accessToken = token;\n\n if (interceptors?.afterLogin) {\n req.additionalData = { user };\n res.locals.additional = { user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n res.status(200).json(req.responseData);\n } else if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.status(200).send();\n }\n ),\n\n /**\n * Creates a new user account using the userService\n */\n signup: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterSignup) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 201;\n res.locals.status = 201;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete user[key as keyof User];\n });\n\n res.status(201).json({ data: user });\n }\n ),\n /**\n * Marks user account as self-deleted by setting deletedSelfAccountAt timestamp\n */\n deleteMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const userId = req.user!.id;\n\n const updatedUser = (await userService.updateOne(\n { id: userId },\n {\n deletedSelfAccountAt: new Date().toISOString(),\n },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterDeleteMe) {\n req.responseData = { data: updatedUser };\n res.locals.data = { data: updatedUser };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete updatedUser[key as keyof User];\n });\n\n res.status(200).json({\n message: \"Account deleted successfully\",\n });\n }\n ),\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const { currentPassword, newPassword } = req.body;\n\n if (!currentPassword || !newPassword)\n return next(\n new AppError(\"currentPassword and newPassword are required\", 400)\n );\n\n const user = req.user;\n\n if (!user || user?.isActive === false || user?.deletedSelfAccountAt)\n return next(new AppError(\"User not found!\", 404));\n\n // Check if the current password is correct\n const isPasswordCorrect = await authService.isCorrectPassword(\n String(currentPassword),\n String(user.password)\n );\n\n const configs = getArkosConfig();\n const initAuthConfigs = configs?.authentication;\n\n if (!isPasswordCorrect)\n return next(new AppError(\"Current password is incorrect.\", 400));\n\n // Check password strength (optional but recommended)\n if (\n !authService.isPasswordStrong(String(newPassword)) &&\n !configs?.validation\n ) {\n return next(\n new AppError(\n initAuthConfigs?.passwordValidation?.message ||\n \"The new password must contain at least one uppercase letter, one lowercase letter, and one number\",\n 400\n )\n );\n }\n\n // Update the password\n await userService.updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()),\n }\n );\n\n if (interceptors?.afterUpdatePassword) {\n req.additionalData = {\n user,\n };\n req.responseData = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n res.locals.data = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({\n status: \"success\",\n message: \"Password updated successfully!\",\n });\n }\n ),\n\n findManyAuthAction: catchAsync(\n async (_: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const authActions = authActionService.getAll()?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n\n findOneAuthAction: catchAsync(\n async (req: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const resourceName = req.params?.resourceName;\n\n if (!resourceName)\n throw new AppError(`Please provide a resoureName`, 400);\n\n const authActions = authActionService\n .getByResource(req.params?.resourceName)\n ?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n if (!authActions)\n throw new AppError(\n `No auth action with resource name ${resourceName}`,\n 404\n );\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;AAAA,qFAA4D;AAC5D,iFAAwD;AAGxD,kEAAyC;AACzC,uDAAmD;AAEnD,sEAA6C;AAC7C,yCAA8C;AAC9C,qFAMiD;AACjD,+FAAqE;AAKxD,QAAA,yBAAyB,GAAG;IACvC,QAAQ,EAAE,KAAK;CAChB,CAAC;AAQK,MAAM,qBAAqB,GAAG,KAAK,EAAE,eAAoB,EAAE,EAAE,EAAE;IACpE,MAAM,WAAW,GAAG,IAAI,0BAAW,C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AAC,CAAC,UAAU,EAAE,EAAE;gBACnB,IAAI,WAAW,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS;oBACjD,OAAQ,UAAkB,EAAE,KAAK,CAAC;gBACpC,OAAO,UAAU,CAAC;YACpB,CAAC,CAAC,CAAC;YAEL,IAAI,CAAC,WAAW;gBACd,MAAM,IAAI,mBAAQ,CAChB,qCAAqC,YAAY,EAAE,EACnD,GAAG,CACJ,CAAC;YAEJ,GAAG,CAAC,IAAI,CAAC;gBACP,KAAK,EAAE,WAAW,CAAC,MAAM;gBACzB,OAAO,EAAE,WAAW,CAAC,MAAM;gBAC3B,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC,CACF;KACF,CAAC;AACJ,CAAC,CAAC;AAlaW,QAAA,qBAAqB,yBAkahC","sourcesContent":["import catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { CookieOptions } from \"express\";\nimport { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"../../types\";\nimport authService from \"./auth.service\";\nimport { BaseService } from \"../base/base.service\";\nimport { User } from \"../../types\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n createPrismaWhereClause,\n determineUsernameField,\n getNestedValue,\n MsDuration,\n toMs,\n} from \"./utils/helpers/auth.controller.helpers\";\nimport authActionService from \"./utils/services/auth-action.service\";\n\n/**\n * Default fields to exclude from user object when returning to client\n */\nexport const defaultExcludedUserFields = {\n password: false,\n};\n\n/**\n * Factory function to create authentication controller with configurable interceptors\n *\n * @param interceptors - Optional middleware functions to execute after controller actions\n * @returns An object containing all authentication controller methods\n */\nexport const authControllerFactory = async (interceptors: any = {}) => {\n const userService = new BaseService(\"user\");\n\n return {\n /**\n * Retrieves the current authenticated user's information\n */\n getMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.findOne(\n { id: req.user!.id },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterGetMe) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Updates the current authenticated user's information\n */\n updateMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (\"password\" in req.body)\n throw new AppError(\n \"In order to update password use the update-password endpoint.\",\n 400,\n {},\n \"InvalidFieldPassword\"\n );\n\n const user = (await userService.updateOne(\n { id: req.user!.id },\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n if (user) delete user[key as keyof User];\n });\n\n if (interceptors?.afterUpdateMe) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({ data: user });\n }\n ),\n\n /**\n * Logs out the current user by invalidating their access token cookie\n */\n logout: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n res.cookie(\"arkos_access_token\", \"no-token\", {\n expires: new Date(Date.now() + 10 * 1000),\n httpOnly: true,\n });\n\n if (interceptors?.afterLogout) {\n req.responseData = null;\n res.locals.data = null;\n req.responseStatus = 204;\n res.locals.status = 204;\n return next();\n }\n\n res.status(204).json();\n }\n ),\n\n /**\n * Authenticates a user using configurable username field and password\n * Username field can be specified in query parameter or config\n *\n * Supports nested fields and array queries (e.g., \"profile.nickname\", \"phones.some.number\")\n */\n login: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const authConfigs = getArkosConfig()?.authentication;\n\n const usernameField = determineUsernameField(req);\n\n // For the error message, we only care about the top-level field name\n const lastField =\n usernameField.split(\".\")[usernameField.split(\".\").length - 1];\n\n const usernameValue = req.body[lastField];\n\n const { password } = req.body;\n\n if (!usernameValue || !password)\n return next(\n new AppError(`Please provide both ${lastField} and password`, 400)\n );\n\n let whereClause: Record<string, any>;\n\n if (usernameField?.includes?.(\".\")) {\n const valueToFind = getNestedValue(req.body, usernameField);\n if (valueToFind === undefined) {\n return next(new AppError(`Invalid ${usernameField} provided`, 400));\n }\n whereClause = createPrismaWhereClause(usernameField, valueToFind);\n } else {\n whereClause = { [usernameField]: usernameValue };\n }\n\n const user = (await userService.findOne(\n whereClause,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (\n !user ||\n !(await authService.isCorrectPassword(password, user.password))\n ) {\n return next(new AppError(`Incorrect ${lastField} or password`, 401));\n }\n\n const token = authService.signJwtToken(user.id!);\n\n const cookieOptions: CookieOptions = {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ||\n process.env.JWT_COOKIE_HTTP_ONLY === \"true\" ||\n true,\n secure:\n authConfigs?.jwt?.cookie?.secure ||\n process.env.JWT_COOKIE_SECURE === \"true\" ||\n req.secure ||\n req.headers[\"x-forwarded-proto\"] === \"https\",\n sameSite:\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n (process.env.NODE_ENV === \"production\" ? \"none\" : \"lax\"),\n };\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n req.responseData = { accessToken: token };\n res.locals.data = { accessToken: token };\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.cookie(\"arkos_access_token\", token, cookieOptions);\n\n req.accessToken = token;\n\n if (interceptors?.afterLogin) {\n req.additionalData = { user };\n res.locals.additional = { user };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n if (\n authConfigs?.login?.sendAccessTokenThrough === \"response-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n ) {\n res.status(200).json(req.responseData);\n } else if (\n authConfigs?.login?.sendAccessTokenThrough === \"cookie-only\" ||\n authConfigs?.login?.sendAccessTokenThrough === \"both\" ||\n !authConfigs?.login?.sendAccessTokenThrough\n )\n res.status(200).send();\n }\n ),\n\n /**\n * Creates a new user account using the userService\n */\n signup: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const user = (await userService.createOne(\n req.body,\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterSignup) {\n req.responseData = { data: user };\n res.locals.data = { data: user };\n req.responseStatus = 201;\n res.locals.status = 201;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete user[key as keyof User];\n });\n\n res.status(201).json({ data: user });\n }\n ),\n /**\n * Marks user account as self-deleted by setting deletedSelfAccountAt timestamp\n */\n deleteMe: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const userId = req.user!.id;\n\n const updatedUser = (await userService.updateOne(\n { id: userId },\n {\n deletedSelfAccountAt: new Date().toISOString(),\n },\n req.prismaQueryOptions || {}\n )) as Record<string, any>;\n\n if (interceptors?.afterDeleteMe) {\n req.responseData = { data: updatedUser };\n res.locals.data = { data: updatedUser };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n Object.keys(defaultExcludedUserFields).forEach((key) => {\n delete updatedUser[key as keyof User];\n });\n\n res.status(200).json({\n message: \"Account deleted successfully\",\n });\n }\n ),\n\n /**\n * Updates the password of the authenticated user\n */\n updatePassword: catchAsync(\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n const { currentPassword, newPassword } = req.body;\n\n if (!currentPassword || !newPassword)\n return next(\n new AppError(\"currentPassword and newPassword are required\", 400)\n );\n\n const user = req.user;\n\n if (!user || user?.isActive === false || user?.deletedSelfAccountAt)\n return next(new AppError(\"User not found!\", 404));\n\n // Check if the current password is correct\n const isPasswordCorrect = await authService.isCorrectPassword(\n String(currentPassword),\n String(user.password)\n );\n\n const configs = getArkosConfig();\n const initAuthConfigs = configs?.authentication;\n\n if (!isPasswordCorrect)\n return next(new AppError(\"Current password is incorrect.\", 400));\n\n // Check password strength (optional but recommended)\n if (\n !authService.isPasswordStrong(String(newPassword)) &&\n !configs?.validation\n ) {\n return next(\n new AppError(\n initAuthConfigs?.passwordValidation?.message ||\n \"The new password must contain at least one uppercase letter, one lowercase letter, and one number\",\n 400\n )\n );\n }\n\n // Update the password\n await userService.updateOne(\n { id: user.id },\n {\n password: await authService.hashPassword(newPassword),\n passwordChangedAt: new Date(Date.now()),\n }\n );\n\n if (interceptors?.afterUpdatePassword) {\n req.additionalData = {\n user,\n };\n req.responseData = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n res.locals.data = {\n status: \"success\",\n message: \"Password updated successfully!\",\n };\n req.responseStatus = 200;\n res.locals.status = 200;\n return next();\n }\n\n res.status(200).json({\n status: \"success\",\n message: \"Password updated successfully!\",\n });\n }\n ),\n\n findManyAuthAction: catchAsync(\n async (_: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const authActions = authActionService.getAll()?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n\n findOneAuthAction: catchAsync(\n async (req: ArkosRequest, res: ArkosResponse) => {\n const arkosConfig = getArkosConfig();\n const resourceName = req.params?.resourceName;\n\n if (!resourceName)\n throw new AppError(`Please provide a resoureName`, 400);\n\n const authActions = authActionService\n .getByResource(req.params?.resourceName)\n ?.map((authAction) => {\n if (arkosConfig?.authentication?.mode === \"dynamic\")\n delete (authAction as any)?.roles;\n return authAction;\n });\n\n if (!authActions)\n throw new AppError(\n `No auth action with resource name ${resourceName}`,\n 404\n );\n\n res.json({\n total: authActions.length,\n results: authActions.length,\n data: authActions,\n });\n }\n ),\n };\n};\n"]}
|
|
@@ -16,205 +16,251 @@ const utils_1 = require("../../exports/utils");
|
|
|
16
16
|
const deepmerge_helper_1 = __importDefault(require("../../utils/helpers/deepmerge.helper"));
|
|
17
17
|
class BaseController {
|
|
18
18
|
constructor(modelName) {
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
req.responseData = { data };
|
|
24
|
-
res.locals.data = { data };
|
|
25
|
-
req.responseStatus = 201;
|
|
26
|
-
res.locals.status = 201;
|
|
27
|
-
return next();
|
|
28
|
-
}
|
|
29
|
-
res.status(201).json({ data });
|
|
30
|
-
});
|
|
31
|
-
this.createMany = (0, catch_async_1.default)(async (req, res, next) => {
|
|
32
|
-
const { where, ...queryOptions } = new utils_1.APIFeatures(req, this.modelName).limitFields().filters;
|
|
33
|
-
const data = await this.service.createMany(req.body, (0, deepmerge_helper_1.default)(req.prismaQueryOptions || {}, queryOptions), { user: req?.user, accessToken: req?.accessToken });
|
|
34
|
-
if (!data)
|
|
35
|
-
return next(new app_error_1.default("Failed to create the resources. Please check your input.", 400, { body: req.body }));
|
|
36
|
-
if (this.interceptors.afterCreateMany) {
|
|
37
|
-
req.responseData = { data };
|
|
38
|
-
res.locals.data = { data };
|
|
39
|
-
req.responseStatus = 201;
|
|
40
|
-
res.locals.status = 201;
|
|
41
|
-
return next();
|
|
42
|
-
}
|
|
43
|
-
res.status(201).json({ data });
|
|
44
|
-
});
|
|
45
|
-
this.findMany = (0, catch_async_1.default)(async (req, res, next) => {
|
|
46
|
-
const { where, ...queryOptions } = new utils_1.APIFeatures(req, this.modelName)
|
|
47
|
-
.filter()
|
|
48
|
-
.sort()
|
|
49
|
-
.limitFields()
|
|
50
|
-
.paginate().filters;
|
|
51
|
-
const [data, total] = (await Promise.all([
|
|
52
|
-
this.service.findMany(where, queryOptions, {
|
|
53
|
-
user: req?.user,
|
|
54
|
-
accessToken: req?.accessToken,
|
|
55
|
-
}),
|
|
56
|
-
this.service.count(where, {
|
|
57
|
-
user: req?.user,
|
|
58
|
-
accessToken: req?.accessToken,
|
|
59
|
-
}),
|
|
60
|
-
]));
|
|
61
|
-
if (this.interceptors.afterFindMany) {
|
|
62
|
-
req.responseData = { total, results: data.length, data };
|
|
63
|
-
res.locals.data = { total, results: data.length, data };
|
|
64
|
-
req.responseStatus = 200;
|
|
65
|
-
res.locals.status = 200;
|
|
66
|
-
return next();
|
|
67
|
-
}
|
|
68
|
-
res.status(200).json({ total, results: data.length, data });
|
|
69
|
-
});
|
|
70
|
-
this.findOne = (0, catch_async_1.default)(async (req, res, next) => {
|
|
71
|
-
const { where, ...queryOptions } = new utils_1.APIFeatures(req, this.modelName).limitFields().filters;
|
|
72
|
-
const data = await this.service.findOne(req.params, (0, deepmerge_helper_1.default)(req.prismaQueryOptions || {}, queryOptions), { user: req?.user, accessToken: req?.accessToken });
|
|
73
|
-
if (!data) {
|
|
74
|
-
if (Object.keys(req.params).length === 1 &&
|
|
75
|
-
"id" in req.params &&
|
|
76
|
-
req.params.id !== "me") {
|
|
77
|
-
return next(new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} with ID ${req.params?.id} not found`, 404, {}, "NotFound"));
|
|
19
|
+
this.executeOperation = (config) => {
|
|
20
|
+
return (0, catch_async_1.default)(async (req, res, next) => {
|
|
21
|
+
if (config.hooks?.beforeQuery) {
|
|
22
|
+
await config.hooks.beforeQuery(req);
|
|
78
23
|
}
|
|
79
|
-
|
|
80
|
-
|
|
24
|
+
if (config.requiresQueryForBulk) {
|
|
25
|
+
if (Object.keys(req.query).every((key) => ["filterMode", "prismaQueryOptions"].includes(key))) {
|
|
26
|
+
return next(new app_error_1.default(`Filter criteria not provided for bulk ${config.operationType.replace(/Many$/, "")}.`, 400, {}, "MissingRequestQueryParameters"));
|
|
27
|
+
}
|
|
81
28
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
req.responseData = { data };
|
|
85
|
-
res.locals.data = { data };
|
|
86
|
-
req.responseStatus = 200;
|
|
87
|
-
res.locals.status = 200;
|
|
88
|
-
return next();
|
|
89
|
-
}
|
|
90
|
-
res.status(200).json({ data });
|
|
91
|
-
});
|
|
92
|
-
this.updateOne = (0, catch_async_1.default)(async (req, res, next) => {
|
|
93
|
-
const { where, ...queryOptions } = new utils_1.APIFeatures(req, this.modelName).limitFields().filters;
|
|
94
|
-
const data = await this.service.updateOne(req.params, req.body, (0, deepmerge_helper_1.default)(req.prismaQueryOptions || {}, queryOptions), { user: req?.user, accessToken: req?.accessToken });
|
|
95
|
-
if (!data) {
|
|
96
|
-
if (Object.keys(req.params).length === 1 && "id" in req.params) {
|
|
97
|
-
return next(new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} with ID ${req.params?.id} not found`, 404, {}, "NotFound"));
|
|
29
|
+
if (config.preventORFilter && req.query.filterMode === "OR") {
|
|
30
|
+
throw new app_error_1.default(`req.query.filterMode === OR is not valid for ${config.operationType} operation`, 400);
|
|
98
31
|
}
|
|
99
|
-
|
|
100
|
-
|
|
32
|
+
if (config.preventORFilter)
|
|
33
|
+
req.query.filterMode = "AND";
|
|
34
|
+
let apiFeatures = new utils_1.APIFeatures(req, this.modelName);
|
|
35
|
+
config.queryFeatures.forEach((feature) => {
|
|
36
|
+
switch (feature) {
|
|
37
|
+
case "filter":
|
|
38
|
+
apiFeatures = apiFeatures.filter();
|
|
39
|
+
break;
|
|
40
|
+
case "sort":
|
|
41
|
+
apiFeatures = apiFeatures.sort();
|
|
42
|
+
break;
|
|
43
|
+
case "limitFields":
|
|
44
|
+
apiFeatures = apiFeatures.limitFields();
|
|
45
|
+
break;
|
|
46
|
+
case "paginate":
|
|
47
|
+
apiFeatures = apiFeatures.paginate();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const { where, ...queryOptions } = apiFeatures.filters;
|
|
52
|
+
if (config.hooks?.afterQuery)
|
|
53
|
+
await config.hooks.afterQuery({ where, queryOptions }, req);
|
|
54
|
+
let serviceArgs = this.buildServiceArgs(config, req, where, queryOptions);
|
|
55
|
+
if (config.hooks?.beforeService)
|
|
56
|
+
serviceArgs = await config.hooks.beforeService(serviceArgs, req);
|
|
57
|
+
const serviceMethod = this.service[config.serviceMethod];
|
|
58
|
+
let result = await serviceMethod.apply(this.service, serviceArgs);
|
|
59
|
+
if (config.hooks?.afterService)
|
|
60
|
+
result = await config.hooks.afterService(result, req);
|
|
61
|
+
let data = result;
|
|
62
|
+
let additionalData = null;
|
|
63
|
+
if (config.operationType === "findMany") {
|
|
64
|
+
const [records, total] = await Promise.all([
|
|
65
|
+
result,
|
|
66
|
+
this.service.count(where, {
|
|
67
|
+
user: req?.user,
|
|
68
|
+
accessToken: req?.accessToken,
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
data = records;
|
|
72
|
+
additionalData = { total, results: records.length };
|
|
101
73
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
74
|
+
const error = config.errorHandler
|
|
75
|
+
? config.errorHandler(data, req, this.modelName)
|
|
76
|
+
: this.defaultErrorHandler(data, req, config.operationType);
|
|
77
|
+
if (error)
|
|
78
|
+
return next(error);
|
|
79
|
+
let responseData = config.responseBuilder
|
|
80
|
+
? config.responseBuilder(data, additionalData)
|
|
81
|
+
: this.defaultResponseBuilder(data, additionalData, config.operationType);
|
|
82
|
+
if (config.hooks?.beforeResponse) {
|
|
83
|
+
responseData = await config.hooks.beforeResponse(responseData, req);
|
|
84
|
+
}
|
|
85
|
+
const interceptorName = `after${config.operationType.charAt(0).toUpperCase()}${config.operationType.slice(1)}`;
|
|
86
|
+
if (this.interceptors[interceptorName]) {
|
|
87
|
+
this.setResponseData(req, res, responseData, config.successStatus);
|
|
88
|
+
return next();
|
|
89
|
+
}
|
|
90
|
+
if (config.operationType === "deleteOne")
|
|
91
|
+
return res.status(config.successStatus).send();
|
|
92
|
+
res.status(config.successStatus).json(responseData);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
this.createOne = this.executeOperation({
|
|
96
|
+
operationType: "createOne",
|
|
97
|
+
serviceMethod: "createOne",
|
|
98
|
+
successStatus: 201,
|
|
99
|
+
queryFeatures: ["limitFields"],
|
|
100
|
+
usesRequestBody: true,
|
|
111
101
|
});
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
req.query.filterMode = "AND";
|
|
119
|
-
const { where, ...queryOptions } = new utils_1.APIFeatures(req, this.modelName)
|
|
120
|
-
.filter()
|
|
121
|
-
.sort()
|
|
122
|
-
.limitFields()
|
|
123
|
-
.paginate().filters;
|
|
124
|
-
delete queryOptions.include;
|
|
125
|
-
const data = (await this.service.updateMany(where, req.body, queryOptions, { user: req?.user, accessToken: req?.accessToken }));
|
|
126
|
-
if (!data || data.count === 0)
|
|
127
|
-
return next(new app_error_1.default(`${(0, pluralize_1.default)((0, change_case_helpers_1.pascalCase)(String(this.modelName)))} not found`, 404));
|
|
128
|
-
if (this.interceptors.afterUpdateMany) {
|
|
129
|
-
req.responseData = { results: data.count, data };
|
|
130
|
-
res.locals.data = { results: data.count, data };
|
|
131
|
-
req.responseStatus = 200;
|
|
132
|
-
res.locals.status = 200;
|
|
133
|
-
return next();
|
|
134
|
-
}
|
|
135
|
-
res.status(200).json({ results: data.count, data });
|
|
102
|
+
this.createMany = this.executeOperation({
|
|
103
|
+
operationType: "createMany",
|
|
104
|
+
serviceMethod: "createMany",
|
|
105
|
+
successStatus: 201,
|
|
106
|
+
queryFeatures: ["limitFields"],
|
|
107
|
+
usesRequestBody: true,
|
|
136
108
|
});
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (this.interceptors.afterBatchUpdate) {
|
|
143
|
-
req.responseData = { results: data.length, data };
|
|
144
|
-
res.locals.data = { results: data.length, data };
|
|
145
|
-
req.responseStatus = 200;
|
|
146
|
-
res.locals.status = 200;
|
|
147
|
-
return next();
|
|
148
|
-
}
|
|
149
|
-
res.status(200).json({ results: data.length, data });
|
|
109
|
+
this.findMany = this.executeOperation({
|
|
110
|
+
operationType: "findMany",
|
|
111
|
+
serviceMethod: "findMany",
|
|
112
|
+
successStatus: 200,
|
|
113
|
+
queryFeatures: ["filter", "sort", "limitFields", "paginate"],
|
|
150
114
|
});
|
|
151
|
-
this.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (Object.keys(req.params).length === 1 && "id" in req.params) {
|
|
158
|
-
return next(new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} with ID ${req.params?.id} not found`, 404, {}, "NotFound"));
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
return next(new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} not found`, 404, {}, "NotFound"));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (this.interceptors.afterDeleteOne) {
|
|
165
|
-
req.additionalData = { data };
|
|
166
|
-
res.locals.additionalData = { data };
|
|
167
|
-
req.responseStatus = 204;
|
|
168
|
-
res.locals.status = 204;
|
|
169
|
-
return next();
|
|
170
|
-
}
|
|
171
|
-
res.status(204).send();
|
|
115
|
+
this.findOne = this.executeOperation({
|
|
116
|
+
operationType: "findOne",
|
|
117
|
+
serviceMethod: "findOne",
|
|
118
|
+
successStatus: 200,
|
|
119
|
+
queryFeatures: ["limitFields"],
|
|
120
|
+
usesRequestParams: true,
|
|
172
121
|
});
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const { where } = new utils_1.APIFeatures(req, this.modelName).filter().filters;
|
|
181
|
-
const data = await this.service.deleteMany(where, {
|
|
182
|
-
user: req?.user,
|
|
183
|
-
accessToken: req?.accessToken,
|
|
184
|
-
});
|
|
185
|
-
if (!data || data.count === 0) {
|
|
186
|
-
return next(new app_error_1.default(`No records found to delete`, 404, {}, "NotFound"));
|
|
187
|
-
}
|
|
188
|
-
if (this.interceptors.afterDeleteMany) {
|
|
189
|
-
req.responseData = { results: data.count, data };
|
|
190
|
-
res.locals.data = { results: data.count, data };
|
|
191
|
-
req.responseStatus = 200;
|
|
192
|
-
res.locals.status = 200;
|
|
193
|
-
return next();
|
|
194
|
-
}
|
|
195
|
-
res.status(200).json({ results: data.count, data });
|
|
122
|
+
this.updateOne = this.executeOperation({
|
|
123
|
+
operationType: "updateOne",
|
|
124
|
+
serviceMethod: "updateOne",
|
|
125
|
+
successStatus: 200,
|
|
126
|
+
queryFeatures: ["limitFields"],
|
|
127
|
+
usesRequestParams: true,
|
|
128
|
+
usesRequestBody: true,
|
|
196
129
|
});
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
130
|
+
this.updateMany = this.executeOperation({
|
|
131
|
+
operationType: "updateMany",
|
|
132
|
+
serviceMethod: "updateMany",
|
|
133
|
+
successStatus: 200,
|
|
134
|
+
queryFeatures: ["filter", "sort", "limitFields", "paginate"],
|
|
135
|
+
requiresQueryForBulk: true,
|
|
136
|
+
preventORFilter: true,
|
|
137
|
+
usesRequestBody: true,
|
|
138
|
+
});
|
|
139
|
+
this.batchUpdate = this.executeOperation({
|
|
140
|
+
operationType: "batchUpdate",
|
|
141
|
+
serviceMethod: "batchUpdate",
|
|
142
|
+
successStatus: 200,
|
|
143
|
+
queryFeatures: ["limitFields"],
|
|
144
|
+
usesRequestBody: true,
|
|
145
|
+
});
|
|
146
|
+
this.deleteOne = this.executeOperation({
|
|
147
|
+
operationType: "deleteOne",
|
|
148
|
+
serviceMethod: "deleteOne",
|
|
149
|
+
successStatus: 204,
|
|
150
|
+
queryFeatures: [],
|
|
151
|
+
usesRequestParams: true,
|
|
152
|
+
});
|
|
153
|
+
this.deleteMany = this.executeOperation({
|
|
154
|
+
operationType: "deleteMany",
|
|
155
|
+
serviceMethod: "deleteMany",
|
|
156
|
+
successStatus: 200,
|
|
157
|
+
queryFeatures: ["filter"],
|
|
158
|
+
requiresQueryForBulk: true,
|
|
159
|
+
preventORFilter: true,
|
|
160
|
+
});
|
|
161
|
+
this.batchDelete = this.executeOperation({
|
|
162
|
+
operationType: "batchDelete",
|
|
163
|
+
serviceMethod: "batchDelete",
|
|
164
|
+
successStatus: 200,
|
|
165
|
+
queryFeatures: [],
|
|
166
|
+
usesRequestBody: true,
|
|
212
167
|
});
|
|
213
168
|
const components = (0, dynamic_loader_1.getModuleComponents)(modelName);
|
|
214
169
|
this.modelName = modelName;
|
|
215
170
|
this.service = new base_service_1.BaseService(modelName);
|
|
216
171
|
this.interceptors = components?.interceptors || {};
|
|
217
172
|
}
|
|
173
|
+
setResponseData(req, res, data, status) {
|
|
174
|
+
req.responseData = data;
|
|
175
|
+
res.locals.data = data;
|
|
176
|
+
req.responseStatus = status;
|
|
177
|
+
res.locals.status = status;
|
|
178
|
+
if (status === 204) {
|
|
179
|
+
req.additionalData = data;
|
|
180
|
+
res.locals.additionalData = data;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
buildServiceArgs(config, req, where, queryOptions) {
|
|
184
|
+
const context = { user: req?.user, accessToken: req?.accessToken };
|
|
185
|
+
const mergedOptions = (0, deepmerge_helper_1.default)(req.prismaQueryOptions || {}, queryOptions);
|
|
186
|
+
switch (config.operationType) {
|
|
187
|
+
case "createOne":
|
|
188
|
+
case "createMany":
|
|
189
|
+
return [req.body, mergedOptions, context];
|
|
190
|
+
case "findMany":
|
|
191
|
+
return [where, queryOptions, context];
|
|
192
|
+
case "findOne":
|
|
193
|
+
return [req.params, mergedOptions, context];
|
|
194
|
+
case "updateOne":
|
|
195
|
+
return [req.params, req.body, mergedOptions, context];
|
|
196
|
+
case "updateMany":
|
|
197
|
+
delete queryOptions.include;
|
|
198
|
+
return [where, req.body, queryOptions, context];
|
|
199
|
+
case "batchUpdate":
|
|
200
|
+
return [req.body, mergedOptions, context];
|
|
201
|
+
case "deleteOne":
|
|
202
|
+
return [req.params, context];
|
|
203
|
+
case "deleteMany":
|
|
204
|
+
return [where, context];
|
|
205
|
+
case "batchDelete":
|
|
206
|
+
return [req.body, context];
|
|
207
|
+
default:
|
|
208
|
+
throw new Error(`Unknown operation type: ${config.operationType}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
defaultErrorHandler(data, req, operationType) {
|
|
212
|
+
if (!data || (Array.isArray(data) && data.length === 0)) {
|
|
213
|
+
if (operationType.includes("create") || operationType.includes("batch")) {
|
|
214
|
+
return new app_error_1.default("Failed to create the resources. Please check your input.", 400, { body: req.body });
|
|
215
|
+
}
|
|
216
|
+
if (operationType === "findOne" ||
|
|
217
|
+
operationType === "updateOne" ||
|
|
218
|
+
operationType === "deleteOne") {
|
|
219
|
+
if (Object.keys(req.params).length === 1 &&
|
|
220
|
+
"id" in req.params &&
|
|
221
|
+
req.params.id !== "me") {
|
|
222
|
+
return new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} with ID ${req.params?.id} not found`, 404, {}, "NotFound");
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return new app_error_1.default(`${(0, change_case_helpers_1.pascalCase)(String(this.modelName))} not found`, 404, {}, "NotFound");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (operationType === "updateMany" || operationType === "deleteMany") {
|
|
229
|
+
const isUpdate = operationType === "updateMany";
|
|
230
|
+
return new app_error_1.default(isUpdate
|
|
231
|
+
? `${(0, pluralize_1.default)((0, change_case_helpers_1.pascalCase)(String(this.modelName)))} not found`
|
|
232
|
+
: `No records found to delete`, 404, {}, "NotFound");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (data &&
|
|
236
|
+
typeof data === "object" &&
|
|
237
|
+
"count" in data &&
|
|
238
|
+
data.count === 0) {
|
|
239
|
+
return new app_error_1.default(operationType === "updateMany"
|
|
240
|
+
? `${(0, pluralize_1.default)((0, change_case_helpers_1.pascalCase)(String(this.modelName)))} not found`
|
|
241
|
+
: `No records found to delete`, 404, {}, "NotFound");
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
defaultResponseBuilder(data, additionalData, operationType) {
|
|
246
|
+
if (operationType === "findMany" && additionalData) {
|
|
247
|
+
return {
|
|
248
|
+
total: additionalData.total,
|
|
249
|
+
results: additionalData.results,
|
|
250
|
+
data,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (operationType.includes("Many") &&
|
|
254
|
+
data &&
|
|
255
|
+
typeof data === "object" &&
|
|
256
|
+
"count" in data) {
|
|
257
|
+
return { results: data.count, data };
|
|
258
|
+
}
|
|
259
|
+
if (operationType.includes("batch") && Array.isArray(data)) {
|
|
260
|
+
return { results: data.length, data };
|
|
261
|
+
}
|
|
262
|
+
return { data };
|
|
263
|
+
}
|
|
218
264
|
}
|
|
219
265
|
exports.BaseController = BaseController;
|
|
220
266
|
exports.getAvailableResources = (0, catch_async_1.default)(async (_, res) => {
|