Skip to content

Commit

Permalink
Merge branch 'dev' into #450-택시비용-보여주기
Browse files Browse the repository at this point in the history
  • Loading branch information
ybmin authored Jul 23, 2024
2 parents 7c48579 + e348e63 commit 4b2ca98
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/modules/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ module.exports = {
chat: {
chatImgType: RegExp("^(image/png|image/jpg|image/jpeg)$"),
chatSendType: RegExp("^(text|account)$"),
chatContent: RegExp("^\\s{0,}\\S{1}[\\s\\S]{0,}$"), // 왼쪽 공백 제외 최소 1개 문자
chatContentLength: RegExp("^[\\s\\S]{1,140}$"), // 공백 포함 최대 140문자
},
};
7 changes: 3 additions & 4 deletions src/routes/chats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const express = require("express");
const { body } = require("express-validator");
const validator = require("../middlewares/validator");
const { validateBody } = require("../middlewares/zod");
const { chatsZod } = require("./docs/schemas/chatsSchema");
const patterns = require("../modules/patterns");

const router = express.Router();
Expand Down Expand Up @@ -47,10 +49,7 @@ router.post(
*/
router.post(
"/send",
body("roomId").isMongoId(),
body("type").matches(patterns.chat.chatSendType),
body("content").isString(),
validator,
validateBody(chatsZod.sendChatHandler),
chatsHandlers.sendChatHandler
);

Expand Down
15 changes: 15 additions & 0 deletions src/routes/docs/schemas/chatsSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { z } = require("zod");
const { zodToSchemaObject } = require("../utils");
const { objectId, chat } = require("../../../modules/patterns");

const chatsZod = {
sendChatHandler: z.object({
roomId: z.string().regex(objectId),
type: z.string().regex(chat.chatSendType),
content: z.string().regex(chat.chatContent).regex(chat.chatContentLength),
}),
};

const chatsSchema = zodToSchemaObject(chatsZod);

module.exports = { chatsZod, chatsSchema };
2 changes: 2 additions & 0 deletions src/routes/docs/swaggerDocs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { reportsSchema } = require("./schemas/reportsSchema");
const { roomsSchema } = require("./schemas/roomsSchema");
const { fareSchema } = require("./schemas/fareSchema");
const { chatsSchema } = require("./schemas/chatsSchema");
const reportsDocs = require("./reports");
const logininfoDocs = require("./logininfo");
const locationsDocs = require("./locations");
Expand Down Expand Up @@ -93,6 +94,7 @@ const swaggerDocs = {
...reportsSchema,
...roomsSchema,
...fareSchema,
...chatsSchema,
},
},
};
Expand Down

0 comments on commit 4b2ca98

Please sign in to comment.