From 96c06ab71f8ac775b59a6fa6bd8c1e82800bb4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ti=E1=BA=BFn=20T=C3=A0i?= <63393170+fdhhhdjd@users.noreply.github.com> Date: Tue, 25 Apr 2023 00:12:55 +0700 Subject: [PATCH] #275 [Backend] New Spec 23042023 --- backend-manager-student/src/admin_api/app.js | 2 +- .../admin_api/industry_code.swagger.yaml | 361 ++++++++++++++++++ .../book.controllers/book.controller.js | 25 +- .../industry_code.controller.js | 294 ++++++++++++++ .../industry_code.private.route.js | 47 +++ .../src/admin_api/v1/routes/private.routes.js | 12 +- backend-manager-student/src/cron_job/cron.js | 2 +- .../controllers/cron_book.controller.js | 26 ++ ...oler.js => cron_borrow_book.controller.js} | 0 .../src/share/configs/message.js | 1 + .../src/share/configs/option.js | 5 + .../src/share/models/book.model.js | 8 + .../src/share/models/industry_code.model.js | 61 +++ .../services/user_service/comment_service.js | 25 +- backend-manager-student/src/user_api/app.js | 2 +- .../v1/Swagger/user_api/comment.swagger.yaml | 292 ++++++++++++++ .../user_api/industry_code.swagger.yaml | 166 ++++++++ .../industry_code.controller.js | 90 +++++ .../src/user_api/v1/routes/general.routes.js | 8 + .../industry_code.route.js | 23 ++ .../managers/student_slice/student_thunk.js | 1 + 21 files changed, 1440 insertions(+), 11 deletions(-) create mode 100644 backend-manager-student/src/admin_api/v1/Swagger/admin_api/industry_code.swagger.yaml create mode 100644 backend-manager-student/src/admin_api/v1/controllers/industry_code.controllers/industry_code.controller.js create mode 100644 backend-manager-student/src/admin_api/v1/routes/industry_code.routes/industry_code.private.route.js create mode 100644 backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_book.controller.js rename backend-manager-student/src/cron_job/v1/cron_student/controllers/{cron_borrow_book.controler.js => cron_borrow_book.controller.js} (100%) create mode 100644 backend-manager-student/src/share/models/industry_code.model.js create mode 100644 backend-manager-student/src/user_api/v1/Swagger/user_api/comment.swagger.yaml create mode 100644 backend-manager-student/src/user_api/v1/Swagger/user_api/industry_code.swagger.yaml create mode 100644 backend-manager-student/src/user_api/v1/controllers/industry_code.controllers/industry_code.controller.js create mode 100644 backend-manager-student/src/user_api/v1/routes/industry_code.routes/industry_code.route.js diff --git a/backend-manager-student/src/admin_api/app.js b/backend-manager-student/src/admin_api/app.js index adc0501..8ac7081 100644 --- a/backend-manager-student/src/admin_api/app.js +++ b/backend-manager-student/src/admin_api/app.js @@ -99,7 +99,7 @@ app.use((error, req, res, next) => { const message = error.message || MESSAGES.GENERAL.INTERNAL_SERVER; return res.status(statusCode).json({ status: statusCode, - stack: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_DEV ? error.stack : MESSAGES.MEDIA.STRING_EMPTY, + stack: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_DEV ? error.stack : MESSAGES.GENERAL.STRING_EMPTY, message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_NOT_FOUND), element: message, }); diff --git a/backend-manager-student/src/admin_api/v1/Swagger/admin_api/industry_code.swagger.yaml b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/industry_code.swagger.yaml new file mode 100644 index 0000000..e71e28b --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/industry_code.swagger.yaml @@ -0,0 +1,361 @@ +#!@author Nguyễn Tiến Tài +#!created_at 08/02/2023 +#!description: General +# Info Swagger Admin APi +info: + title: Document Admin + description: CURD industry-code + version: 1.0.0 +servers: + - url: http://localhost:5000 + description: Local development server admin api +# General +components: + # Parameter + parameters: + X-DEVICE-ID: + in: header + name: X-DEVICE-ID + required: true + schema: + type: string + X-OS-TYPE: + in: header + name: X-OS-TYPE + required: true + schema: + type: string + X-OS-VERSION: + in: header + name: X-OS-VERSION + required: true + schema: + type: string + X-APP-VERSION: + in: header + name: X-APP-VERSION + required: true + schema: + type: string + X-DEVICE-NAME: + in: header + name: X-DEVICE-NAME + required: true + schema: + type: string + TOKEN: + in: header + name: Authorization + type: string + description: Bearer Token + required: true + schema: + type: bearerToken + # Unauthorized + responses: + UnauthorizedError: + description: Access token is missing or invalid, or the user does not have access to perform the action,or or Device Invalid + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: 'Unauthorized' + # Fail CURD Fail + ServerCURDFail: + description: CURD Fail !!! + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Service Unavailable + element: + type: object + example: Internal Server Error + ServerFail: + description: Service die + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 503 + message: + type: string + example: Service Unavailable + element: + type: object + example: Out Of Service + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: create IndustryCode +paths: + /v1/admin/private/industry-code/create: + post: + summary: Create industryCode + tags: [Create industryCode] + operationId: createIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + industry_input: + type: object + properties: + name: + type: string + example: Tai + required: + - name + responses: + 200: + description: Create success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: update IndustryCode + /v1/admin/private/industry-code/update: + post: + summary: Update IndustryCode + tags: [Update IndustryCode] + operationId: updateIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + industry_input: + type: object + properties: + industry_code_id: + type: string + example: 1475825111725506562 + name: + type: string + example: Tai + required: + - industry_code_id + - name + responses: + 200: + description: update success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: delete IndustryCode + /v1/admin/private/industry-code/delete: + post: + summary: Delete IndustryCode + tags: [Delete IndustryCode] + operationId: deleteIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + industry_input: + type: object + properties: + industry_code_id: + type: string + example: 1474830717476143106 + required: + - industry_code_id + responses: + 200: + description: Delete success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 503: + $ref: '#/components/responses/ServerFail' + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: Detail IndustryCode + /v1/admin/private/industry-code/detail/:industry_code_id: + get: + summary: Detail IndustryCode + tags: [Detail IndustryCode] + operationId: detailIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: Detail success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: Get all IndustryCode + /v1/admin/private/industry-code/all: + get: + summary: Get all IndustryCode + tags: [Get all IndustryCode] + operationId: getAllIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' diff --git a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js index 6a0b3eb..8260df9 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js @@ -21,7 +21,7 @@ const bookController = { /** * @author Nguyễn Tiến Tài * @created_at 03/02/2023 - * @created_at 27/03/2023, 14/04/2023 + * @created_at 27/03/2023, 14/04/2023, 24/04/2023 * @description create book * @function createBook * @return {Object:{Number,String}} @@ -33,6 +33,7 @@ const bookController = { image_uri, description, page_number, + industry_code_id, bookshelf, language, quantity, @@ -51,6 +52,7 @@ const bookController = { || !quantity || !public_id_image || !page_number + || !industry_code_id ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, @@ -83,6 +85,7 @@ const bookController = { public_id_image, page_number, real_quantity: quantity, + industry_code_id, }; try { // create book database @@ -137,7 +140,7 @@ const bookController = { /** * @author Nguyễn Tiến Tài * @created_at 03/02/2023 - * @updated_at 17/04/2023 + * @updated_at 17/04/2023 24/04/2023 * @description update book * @function updateBook * @return {Object:{Number,String}} @@ -156,6 +159,7 @@ const bookController = { page_number, public_id_image, book_categories_array, + industry_code_id, } = req.body.input.book_input; // Check input @@ -171,9 +175,18 @@ const bookController = { // Check Input is empty if ( - [name, author_id, image_uri, description, bookshelf, language, quantity, public_id_image, page_number].some( - (field) => field !== undefined && field.trim() === '', - ) + [ + name, + author_id, + industry_code_id, + image_uri, + description, + bookshelf, + language, + quantity, + public_id_image, + page_number, + ].some((field) => field !== undefined && field.trim() === '') ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, @@ -216,6 +229,7 @@ const bookController = { status, public_id_image, page_number, + industry_code_id, real_quantity: Number(book[0].quantity) + Number(quantity_update), }; try { @@ -440,6 +454,7 @@ const bookController = { }); } } catch (error) { + console.error('error::::', error); return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), diff --git a/backend-manager-student/src/admin_api/v1/controllers/industry_code.controllers/industry_code.controller.js b/backend-manager-student/src/admin_api/v1/controllers/industry_code.controllers/industry_code.controller.js new file mode 100644 index 0000000..65d4fe0 --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/controllers/industry_code.controllers/industry_code.controller.js @@ -0,0 +1,294 @@ +//! SHARE +const HELPER = require('../../../../share/utils/helper'); +const RANDOMS = require('../../../../share/utils/random'); +const CONSTANTS = require('../../../../share/configs/constants'); +const MESSAGES = require('../../../../share/configs/message'); + +//! MIDDLEWARE +const { returnReasons } = require('../../../../share/middleware/handle_error'); + +//! MODEL +const industry_code_model = require('../../../../share/models/industry_code.model'); + +const industryCodeController = { + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Create Industry Code + * @function InsertIndustryCode + * @return {Object} + */ + InsertIndustryCode: async (req, res) => { + const { name } = req.body.input.industry_input; + + // Check input + if (!name) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_INPUT, + }, + }); + } + try { + // create Category database + let err; + let result; + [err, result] = await HELPER.handleRequest( + industry_code_model.createIndustryCode({ + industry_code_id: RANDOMS.createID(), + name, + }), + ); + if (result) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result[0].industry_code_id, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description update Industry Code + * @function updateIndustryCode + * @return {Object} + */ + updateIndustryCode: async (req, res) => { + const { industry_code_id, name } = req.body.input.industry_input; + + // Check input + if (!industry_code_id || !HELPER.validateBigInt(industry_code_id)) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_INPUT, + }, + }); + } + + // Check Input is empty + if (name !== undefined && name.trim() === '') { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_MUTILP_FIELD, + }, + }); + } + + try { + // update IndustryCode database + let err; + let result; + [err, result] = await HELPER.handleRequest( + industry_code_model.updateIndustryCode( + { + name, + }, + { + industry_code_id, + isdeleted: CONSTANTS.DELETED_DISABLE, + }, + { + industry_code_id: 'industry_code_id', + }, + ), + ); + if (result) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result[0].industry_code_id, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description delete Industry Code + * @function deleteIndustryCode + * @return {Object} + */ + deleteIndustryCode: async (req, res) => { + const { industry_code_id } = req.body.input.industry_input; + + // Check input + if (!industry_code_id) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_INPUT, + }, + }); + } + try { + // Check account already delete + const result_industry_code_detail = await industry_code_model.getIndustryCodeById( + { industry_code_id, isdeleted: CONSTANTS.DELETED_ENABLE }, + { industry_code_id: 'industry_code_id' }, + ); + if (result_industry_code_detail.length > 0) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.EXITS_DELETE_INDUSTRY_CODE, + }, + }); + } + // Delete industry_code database + let err; + let result; + [err, result] = await HELPER.handleRequest( + industry_code_model.updateIndustryCode( + { + isdeleted: CONSTANTS.DELETED_ENABLE, + }, + { industry_code_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { industry_code_id: 'industry_code_id' }, + ), + ); + if (result) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result[0].industry_code_id, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description detail Industry Code + * @function getDetailIndustryCode + * @return {Object} + */ + getDetailIndustryCode: async (req, res) => { + const industry_code_id = req.params.industry_code_id; + // Check input + if (!industry_code_id) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_INPUT, + }, + }); + } + try { + // detail industry_code database + const result_industry_code_detail = await industry_code_model.getIndustryCodeById( + { industry_code_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + '*', + ); + if (result_industry_code_detail) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_industry_code_detail[0], + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Get all Industry Code + * @function getAllIndustryCode + * @return {Object} + */ + getAllIndustryCode: async (req, res) => { + try { + // detail industry_code database + const result_industry_code_detail = await industry_code_model.getAllIndustryCode( + { isdeleted: CONSTANTS.DELETED_DISABLE }, + '*', + ); + if (result_industry_code_detail) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_industry_code_detail, + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, +}; +module.exports = industryCodeController; diff --git a/backend-manager-student/src/admin_api/v1/routes/industry_code.routes/industry_code.private.route.js b/backend-manager-student/src/admin_api/v1/routes/industry_code.routes/industry_code.private.route.js new file mode 100644 index 0000000..0aa799e --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/routes/industry_code.routes/industry_code.private.route.js @@ -0,0 +1,47 @@ +//! LIBRARY +const router = require('express').Router(); + +//! CONTROLLER USER +const industryCodeController = require('../../controllers/industry_code.controllers/industry_code.controller'); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route create industry code + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/create', industryCodeController.InsertIndustryCode); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route update industry code + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/update', industryCodeController.updateIndustryCode); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route delete industry code + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/delete', industryCodeController.deleteIndustryCode); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route get detail industry code + * @param {('GET')} [method='GET'] The request's method + */ +router.get('/detail/:industry_code_id', industryCodeController.getDetailIndustryCode); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route get all industry code + * @param {('GET')} [method='GET'] The request's method + */ +router.get('/all', industryCodeController.getAllIndustryCode); + +module.exports = router; diff --git a/backend-manager-student/src/admin_api/v1/routes/private.routes.js b/backend-manager-student/src/admin_api/v1/routes/private.routes.js index c5dae16..6a45a47 100644 --- a/backend-manager-student/src/admin_api/v1/routes/private.routes.js +++ b/backend-manager-student/src/admin_api/v1/routes/private.routes.js @@ -9,6 +9,7 @@ const categoriesPrivateRouter = require('./categories.routes/categories.private. const borrowBookPrivateRouter = require('./borrow_book_routes/borrow_book_private.route'); const studentPrivateRouter = require('./student.routes/student.private.route'); const categoriesBookPrivateRouter = require('./book_categories.routes/book_categories.private.route'); +const industryCodePrivateRouter = require('./industry_code.routes/industry_code.private.route'); /** * @author Nguyễn Tiến Tài @@ -49,15 +50,22 @@ router_private.use('/borrow_book', borrowBookPrivateRouter); /** * @author Nguyễn Tiến Tài * @created_at 24/03/2023 - * @description Route borrow book + * @description Route student */ router_private.use('/student', studentPrivateRouter); /** * @author Nguyễn Tiến Tài * @created_at 15/04/2023 - * @description Route categories Book book + * @description Route categories */ router_private.use('/book-categories', categoriesBookPrivateRouter); +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route industry code + */ +router_private.use('/industry-code', industryCodePrivateRouter); + module.exports = router_private; diff --git a/backend-manager-student/src/cron_job/cron.js b/backend-manager-student/src/cron_job/cron.js index 9d0f25b..0c34b21 100644 --- a/backend-manager-student/src/cron_job/cron.js +++ b/backend-manager-student/src/cron_job/cron.js @@ -7,7 +7,7 @@ const cron = require('node-cron'); //! MODEL const cron_verification_student = require('./v1/cron_student/controllers/cron_verification.controller'); const cron_reset_password_student = require('./v1/cron_student/controllers/cron_reset_password.controller'); -const cron_borrow_book_student = require('./v1/cron_student/controllers/cron_borrow_book.controler'); +const cron_borrow_book_student = require('./v1/cron_student/controllers/cron_borrow_book.controller'); /** * @author Nguyễn Tiến Tài diff --git a/backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_book.controller.js b/backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_book.controller.js new file mode 100644 index 0000000..6d029c4 --- /dev/null +++ b/backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_book.controller.js @@ -0,0 +1,26 @@ +//! SHARE +const CONSTANTS = require('../../../../share/configs/constants'); +const { handleException } = require('../../../../share/utils/redis_pub_sub_helper'); + +//! MODEL +const { list_comment_id } = require('../../../../share/services/user_service/comment_service'); + +module.exports = { + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description cron_delete_comment_book_student + * @function cron_delete_comment_book_student + */ + async cron_delete_comment_book_student() { + try { + // Get all table book List + const bookList = await list_comment_id(); + + console.info('listBook::::', bookList); + } catch (error) { + console.error('UPDATE FAIL!', error); + handleException(error, CONSTANTS.NAME_SERVER.CRON); + } + }, +}; diff --git a/backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_borrow_book.controler.js b/backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_borrow_book.controller.js similarity index 100% rename from backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_borrow_book.controler.js rename to backend-manager-student/src/cron_job/v1/cron_student/controllers/cron_borrow_book.controller.js diff --git a/backend-manager-student/src/share/configs/message.js b/backend-manager-student/src/share/configs/message.js index 6f03cc1..f25f05d 100644 --- a/backend-manager-student/src/share/configs/message.js +++ b/backend-manager-student/src/share/configs/message.js @@ -50,6 +50,7 @@ module.exports = { EXITS_DELETE_BOOK: 'Book already delete!', EXITS_DELETE_AUTHOR: 'Author already delete!', EXITS_DELETE_CATEGORIES: 'Categories already delete !', + EXITS_DELETE_INDUSTRY_CODE: 'Industry Code already delete !', EXITS_UPDATE_BORROW: 'Already update borrow book !', EXITS_CAN_ONLY_TOW_BORROW: 'You can only borrow tow book!', EXITS_EMAIL: 'Email not exit!', diff --git a/backend-manager-student/src/share/configs/option.js b/backend-manager-student/src/share/configs/option.js index daa8ff3..f04e106 100644 --- a/backend-manager-student/src/share/configs/option.js +++ b/backend-manager-student/src/share/configs/option.js @@ -2,6 +2,11 @@ const CONSTANTS = require('./constants'); module.exports = { + /** + * @author Nguyễn Tiến Tài + * @created_at 01/01/2023 + * @description setup Swagger + */ SWAGGER_ADMIN: { definition: { openapi: CONSTANTS.OPEN_API_SWAGGER, diff --git a/backend-manager-student/src/share/models/book.model.js b/backend-manager-student/src/share/models/book.model.js index a720103..8f27c4b 100644 --- a/backend-manager-student/src/share/models/book.model.js +++ b/backend-manager-student/src/share/models/book.model.js @@ -30,6 +30,7 @@ module.exports = { const result = await knex('books') .join('authors', 'books.author_id', '=', 'authors.author_id') .leftJoin('book_rates', 'books.book_id', '=', 'book_rates.book_id') + .leftJoin('industry_code', 'books.industry_code_id', '=', 'industry_code.industry_code_id') .where({ 'books.isdeleted': student_query.isdeleted, 'books.book_id': student_query.book_id, @@ -41,6 +42,9 @@ module.exports = { gender_author: 'authors.gender', image_author: 'authors.avatar_uri', }, + { + industry_code_name: 'industry_code.name', + }, { star: 'book_rates.rating', }, @@ -71,6 +75,7 @@ module.exports = { getAllBook: async () => { const result = await knex('books') .join('authors', 'books.author_id', '=', 'authors.author_id') + .leftJoin('industry_code', 'books.industry_code_id', '=', 'industry_code.industry_code_id') .leftJoin('book_rates', 'books.book_id', '=', 'book_rates.book_id') .where('books.isdeleted', '=', CONSTANTS.DELETED_DISABLE) .select( @@ -80,6 +85,9 @@ module.exports = { gender_author: 'authors.gender', image_author: 'authors.avatar_uri', }, + { + industry_code_name: 'industry_code.name', + }, { star: 'book_rates.rating', }, diff --git a/backend-manager-student/src/share/models/industry_code.model.js b/backend-manager-student/src/share/models/industry_code.model.js new file mode 100644 index 0000000..e7f44ee --- /dev/null +++ b/backend-manager-student/src/share/models/industry_code.model.js @@ -0,0 +1,61 @@ +//! DATABASE +const knex = require('../db/postgresql'); + +module.exports = { + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description create Industry Code + */ + createIndustryCode: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('industry_code') + .insert(data) + .onConflict('industry_code_id') + .merge() + .returning(['industry_code_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), + + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description get Industry Code id + */ + getIndustryCodeById: async (student_query, return_data) => { + const result = await knex('industry_code').select(return_data).where(student_query); + return result; + }, + + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Update Industry Code + */ + updateIndustryCode: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('industry_code').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), + + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Get all Industry Code + */ + getAllIndustryCode: async (student_query, return_data) => { + const result = await knex('industry_code') + .select(return_data) + .where(student_query) + .orderBy('updated_at', 'desc'); + return result; + }, +}; diff --git a/backend-manager-student/src/share/services/user_service/comment_service.js b/backend-manager-student/src/share/services/user_service/comment_service.js index 5066791..054d991 100644 --- a/backend-manager-student/src/share/services/user_service/comment_service.js +++ b/backend-manager-student/src/share/services/user_service/comment_service.js @@ -45,10 +45,32 @@ const list_comment = async (match, search_data) => { const list_comment = await Promise.all(userPromises); return list_comment; }; - +/** + * @author Nguyễn Tiến Tài + * @created_at 22/04/2023 + * @description list comment slug + * @function list_comment_slug + */ const list_comment_slug = async (match, search_data) => await COMMENT.find(match, search_data).sort({ full_slug: 1 }).lean(); +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description list comment id + * @function list_comment_id + */ +const list_comment_id = async () => + new Promise((resolve, reject) => { + COMMENT.find().exec((error, result) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + }); + /** * @author Nguyễn Tiến Tài * @created_at 13/04/2023 @@ -80,4 +102,5 @@ module.exports = { delete_comment, get_comment_id, list_comment_slug, + list_comment_id, }; diff --git a/backend-manager-student/src/user_api/app.js b/backend-manager-student/src/user_api/app.js index 198dc2a..e602212 100644 --- a/backend-manager-student/src/user_api/app.js +++ b/backend-manager-student/src/user_api/app.js @@ -105,7 +105,7 @@ app.use((error, req, res, next) => { const message = error.message || MESSAGES.GENERAL.INTERNAL_SERVER; return res.status(statusCode).json({ status: statusCode, - stack: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_DEV ? error.stack : MESSAGES.MEDIA.STRING_EMPTY, + stack: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_DEV ? error.stack : MESSAGES.GENERAL.STRING_EMPTY, message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_NOT_FOUND), element: message, }); diff --git a/backend-manager-student/src/user_api/v1/Swagger/user_api/comment.swagger.yaml b/backend-manager-student/src/user_api/v1/Swagger/user_api/comment.swagger.yaml new file mode 100644 index 0000000..c99b91f --- /dev/null +++ b/backend-manager-student/src/user_api/v1/Swagger/user_api/comment.swagger.yaml @@ -0,0 +1,292 @@ +#!@author Nguyễn Tiến Tài +#!created_at 08/02/2023 +#!description: General +# Info Swagger Student APi +info: + title: Document Student + description: CURD Categories + version: 1.0.0 +servers: + - url: http://localhost:5000 + description: Local development server admin api +# General +components: + # Parameter + parameters: + X-DEVICE-ID: + in: header + name: X-DEVICE-ID + required: true + schema: + type: string + X-OS-TYPE: + in: header + name: X-OS-TYPE + required: true + schema: + type: string + X-OS-VERSION: + in: header + name: X-OS-VERSION + required: true + schema: + type: string + X-APP-VERSION: + in: header + name: X-APP-VERSION + required: true + schema: + type: string + X-DEVICE-NAME: + in: header + name: X-DEVICE-NAME + required: true + schema: + type: string + TOKEN: + in: header + name: Authorization + type: string + description: Bearer Token + required: true + schema: + type: bearerToken + # Unauthorized + responses: + UnauthorizedError: + description: Access token is missing or invalid, or the user does not have access to perform the action,or or Device Invalid + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: 'Unauthorized' + # Fail CURD Fail + ServerCURDFail: + description: CURD Fail !!! + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Service Unavailable + element: + type: object + example: Internal Server Error + ServerFail: + description: Service die + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 503 + message: + type: string + example: Service Unavailable + element: + type: object + example: Out Of Service + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: create comment +paths: + /v1/user/private/comment/create: + post: + summary: Create Comment + tags: [Create Comment] + operationId: createComment + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + comment_input: + type: object + properties: + book_id: + type: number + example: 1486078313523838978 + parent_slug: + type: string + example: '' + content: + type: string + example: Hello world + required: + - book_id + - parent_slug + - content + responses: + 200: + description: Create success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: delete comment + /v1/user/private/comment/delete: + post: + summary: Delete Comment + tags: [Delete Comment] + operationId: deleteComment + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + comment_input: + type: object + properties: + comment_id: + type: string + example: 1474830717476143106 + required: + - comment_id + responses: + 200: + description: Delete success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: Get List Comment + /v1/user/comment/all: + get: + summary: Get all Comment + tags: [Get all Comment] + operationId: listComment + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + comment_input: + type: object + properties: + book_id: + type: number + example: 1486078313523838978 + slug: + type: number + example: 1551993628342091778 + required: + - book_id + - slug + responses: + 200: + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' diff --git a/backend-manager-student/src/user_api/v1/Swagger/user_api/industry_code.swagger.yaml b/backend-manager-student/src/user_api/v1/Swagger/user_api/industry_code.swagger.yaml new file mode 100644 index 0000000..7056834 --- /dev/null +++ b/backend-manager-student/src/user_api/v1/Swagger/user_api/industry_code.swagger.yaml @@ -0,0 +1,166 @@ +#!@author Nguyễn Tiến Tài +#!created_at 08/02/2023 +#!description: General +# Info Swagger User APi +info: + title: Document Student + description: CURD CATEGORIES + version: 1.0.0 +servers: + - url: http://localhost:5001 + description: Local development server user api +# General +components: + # Parameter + parameters: + X-DEVICE-ID: + in: header + name: X-DEVICE-ID + required: true + schema: + type: string + X-OS-TYPE: + in: header + name: X-OS-TYPE + required: true + schema: + type: string + X-OS-VERSION: + in: header + name: X-OS-VERSION + required: true + schema: + type: string + X-APP-VERSION: + in: header + name: X-APP-VERSION + required: true + schema: + type: string + X-DEVICE-NAME: + in: header + name: X-DEVICE-NAME + required: true + schema: + type: string + TOKEN: + in: header + name: Authorization + type: string + description: Bearer Token + required: true + schema: + type: bearerToken + # Unauthorized + responses: + UnauthorizedError: + description: Access token is missing or invalid, or the user does not have access to perform the action,or or Device Invalid + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: 'Unauthorized' + # Fail CURD Fail + ServerCURDFail: + description: CURD Fail !!! + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Service Unavailable + element: + type: object + example: Internal Server Error + ServerFail: + description: Service die + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 503 + message: + type: string + example: Service Unavailable + element: + type: object + example: Out Of Service +paths: + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: Detail IndustryCode + /v1/user/private/industry-code/detail/:industry_code_id: + get: + summary: Detail IndustryCode + tags: [Detail IndustryCode] + operationId: detailIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: Detail success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' + #!@author Nguyễn Tiến Tài + #!created_at 24/04/2023 + #!description: Get all IndustryCode + /v1/user/private/industry-code/all: + get: + summary: Get all IndustryCode + tags: [Get all IndustryCode] + operationId: getAllIndustryCode + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' diff --git a/backend-manager-student/src/user_api/v1/controllers/industry_code.controllers/industry_code.controller.js b/backend-manager-student/src/user_api/v1/controllers/industry_code.controllers/industry_code.controller.js new file mode 100644 index 0000000..d41cd75 --- /dev/null +++ b/backend-manager-student/src/user_api/v1/controllers/industry_code.controllers/industry_code.controller.js @@ -0,0 +1,90 @@ +//! SHARE +const CONSTANTS = require('../../../../share/configs/constants'); +const MESSAGES = require('../../../../share/configs/message'); + +//! MIDDLEWARE +const { returnReasons } = require('../../../../share/middleware/handle_error'); + +//! MODEL +const industry_code_model = require('../../../../share/models/industry_code.model'); + +const indusTryCodeController = { + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2022 + * @description detail IndustryCode + * @function getDetailIndustryCode + * @return {Object:{Number,String}} + */ + getDetailIndustryCode: async (req, res) => { + const industry_code_id = req.params.industry_code_id; + // Check input + if (!industry_code_id) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_INPUT, + }, + }); + } + try { + // detail industry_code database + const result_industry_code_detail = await industry_code_model.getIndustryCodeById( + { industry_code_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + '*', + ); + if (result_industry_code_detail) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_industry_code_detail[0], + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2022 + * @description Get all IndustryCode + * @function getAllIndustryCode + * @return {Object} + */ + getAllIndustryCode: async (req, res) => { + try { + // detail Industry Code database + const result_industry_code_detail = await industry_code_model.getAllIndustryCode( + { isdeleted: CONSTANTS.DELETED_DISABLE }, + '*', + ); + if (result_industry_code_detail) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_industry_code_detail, + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, +}; +module.exports = indusTryCodeController; diff --git a/backend-manager-student/src/user_api/v1/routes/general.routes.js b/backend-manager-student/src/user_api/v1/routes/general.routes.js index 77d8e6e..6d472ee 100644 --- a/backend-manager-student/src/user_api/v1/routes/general.routes.js +++ b/backend-manager-student/src/user_api/v1/routes/general.routes.js @@ -7,6 +7,7 @@ const bookRouter = require('./books.routes/book.route'); const authorRouter = require('./author.routes/author.route'); const categoriesRouter = require('./categories.routes/categories.route'); const commentsRouter = require('./comment.routes/comment.route'); +const industryCodePrivateRouter = require('./industry_code.routes/industry_code.route'); /** * @author Nguyễn Tiến Tài @@ -43,4 +44,11 @@ router_general.use('/categories', categoriesRouter); */ router_general.use('/comment', commentsRouter); +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route Industry Code + */ +router_general.use('/industry-code', industryCodePrivateRouter); + module.exports = router_general; diff --git a/backend-manager-student/src/user_api/v1/routes/industry_code.routes/industry_code.route.js b/backend-manager-student/src/user_api/v1/routes/industry_code.routes/industry_code.route.js new file mode 100644 index 0000000..95aaaa9 --- /dev/null +++ b/backend-manager-student/src/user_api/v1/routes/industry_code.routes/industry_code.route.js @@ -0,0 +1,23 @@ +//! LIBRARY +const router = require('express').Router(); + +//! CONTROLLER USER +const industryCodeController = require('../../controllers/industry_code.controllers/industry_code.controller'); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route get detail industry_code + * @param {('POST')} [method='POST'] The request's method + */ +router.get('/detail/:industry_code_id', industryCodeController.getDetailIndustryCode); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/04/2023 + * @description Route get all industry_code + * @param {('POST')} [method='POST'] The request's method + */ +router.get('/all', industryCodeController.getAllIndustryCode); + +module.exports = router; diff --git a/frontend-manager-cms/src/redux/managers/student_slice/student_thunk.js b/frontend-manager-cms/src/redux/managers/student_slice/student_thunk.js index 25714a4..97a5ff3 100644 --- a/frontend-manager-cms/src/redux/managers/student_slice/student_thunk.js +++ b/frontend-manager-cms/src/redux/managers/student_slice/student_thunk.js @@ -236,6 +236,7 @@ export const Edit_Account_Cms_Initial = createAsyncThunk( export const Create_Account_Excel_Cms_Initial = createAsyncThunk( 'admin/cms/account/create/excel', async ({ url_document }, { rejectWithValue }) => { + console.log(url_document, '======'); try { //Call Api axios const response = await REQUEST.post(