diff --git a/src/server/routes/events/deleteEvent.ts b/src/server/routes/events/deleteEvent.ts index fa9b96e..643a6c9 100644 --- a/src/server/routes/events/deleteEvent.ts +++ b/src/server/routes/events/deleteEvent.ts @@ -1,5 +1,4 @@ import {defineSchema} from '../../libs/schema'; -import {z} from 'zod'; import {defineRoute} from '../../libs/route'; import EventService from '../../../service/EventService'; import {stringAsInt} from '../../libs/zodTypes'; @@ -10,7 +9,7 @@ const schema = defineSchema({ }, }); -export default defineRoute('delete', '/event/:eventId?', schema, async (req, res) => { +export default defineRoute('delete', '/event/:eventId', schema, async (req, res) => { const {eventId} = req.params; await EventService.deleteEvent(eventId); diff --git a/src/server/routes/events/getEvent.ts b/src/server/routes/events/getEvent.ts index a052d3e..538c7f2 100644 --- a/src/server/routes/events/getEvent.ts +++ b/src/server/routes/events/getEvent.ts @@ -9,7 +9,7 @@ const schema = defineSchema({ }, }); -export default defineRoute('get', '/event/:eventId?', schema, async (req, res) => { +export default defineRoute('get', '/event/:eventId', schema, async (req, res) => { const {eventId} = req.params; const eventInformation = await EventService.getEvent(eventId); diff --git a/src/server/routes/events/makeEvent.ts b/src/server/routes/events/makeEvent.ts index d829faa..afc9073 100644 --- a/src/server/routes/events/makeEvent.ts +++ b/src/server/routes/events/makeEvent.ts @@ -23,8 +23,8 @@ export default defineRoute('post', '/event', schema, async (req, res) => { const {userId} = req; const {host, category, title, body, imageUuid, startAt, endAt} = req.body; - const Userstatus = await UserService.getUser(userId) - await EventService.makeEvent(Userstatus, host, category, title, body, imageUuid, startAt, endAt); + const user = await UserService.getUser(userId) + await EventService.makeEvent({user, host, category, title, body, imageUuid, startAt, endAt}); res.sendStatus(201); //success }); diff --git a/src/server/routes/events/updateEvent.ts b/src/server/routes/events/updateEvent.ts index 332b238..52de828 100644 --- a/src/server/routes/events/updateEvent.ts +++ b/src/server/routes/events/updateEvent.ts @@ -8,7 +8,7 @@ const schema = defineSchema({ params: { eventId: stringAsInt, }, - query: { + body: { host: z.string().optional(), category: z.string().optional(), title: z.string().optional(), @@ -22,7 +22,7 @@ const schema = defineSchema({ export default defineRoute('patch', '/event/:eventId?', schema, async (req, res) => { const {eventId} = req.params; - await EventService.patchEvent(eventId, req.query); + await EventService.patchEvent(eventId, req.body); return res.send(`event ${eventId}를 업데이트: ${JSON.stringify(req.query)}`); }); diff --git a/src/service/EventService.ts b/src/service/EventService.ts index aa2c1c3..7e83896 100644 --- a/src/service/EventService.ts +++ b/src/service/EventService.ts @@ -1,8 +1,19 @@ import User from '../entity/User'; import Event from '../entity/Event'; +type ModifyEventParams = { + user: User; + host: string; + category: string; + title: string; + body: string; + imageUuid: string; + startAt: Date; + endAt: Date +} + class EventService { - async makeEvent(user: User, host: string, category: string, title: string, body: string, imageUuid: string, startAt: Date, endAt: Date): Promise { + async makeEvent({user, host, category, title, body, imageUuid, startAt, endAt}: ModifyEventParams): Promise { return await Event.create({ user: user, host: host, @@ -19,16 +30,16 @@ class EventService { return await Event.findOne({where: {id: eventId}}); } - async patchEvent(eventId: number, req_query: Object): Promise { + async patchEvent(eventId: number, body: Partial): Promise { const patchevent = await Event.update( {id: eventId}, - req_query + body ); return patchevent.raw; } - async deleteEvent(id: number): Promise { - await Event.delete({id}); + async deleteEvent(eventId: number): Promise { + await Event.delete({id: eventId}); return; } }