Skip to content

Commit

Permalink
refactor: GetEvent, DeleteEvent 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
seohyun-kim committed Feb 6, 2022
1 parent 41dd3d7 commit 28a33b8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/server/routes/events/deleteEvent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {defineSchema} from '../../libs/schema';
import {z} from 'zod';
import {defineRoute} from '../../libs/route';
import {getCustomRepository} from "typeorm";
import EventRepository from "../../libs/application/events/event-repository";
import DeleteEvent from "../../../service/event/DeleteEvent";


const schema = defineSchema({
Expand All @@ -11,10 +10,11 @@ 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 getCustomRepository(EventRepository).deleteEvent(eventId);
return res.send(`event ${eventId}를 삭제했습니다.`);
//res.send();
});
await DeleteEvent.deleteEvent(eventId);
return res.send(`이벤트 ${eventId}를 삭제했습니다.`);

});
3 changes: 2 additions & 1 deletion src/server/routes/events/getEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {z} from 'zod';
import {defineRoute} from '../../libs/route';
import {getCustomRepository} from "typeorm";
import EventRepository from "../../libs/application/events/event-repository";
import GetEvent from "../../../service/event/GetEvent";


const schema = defineSchema({
Expand All @@ -14,6 +15,6 @@ const schema = defineSchema({
export default defineRoute('get', '/event/:eventId?', schema, async (req, res) => {

const {eventId} = req.params;
const Event_Information = await getCustomRepository(EventRepository).getEvent(eventId);
const Event_Information = await GetEvent.getEvent(eventId);
return res.json(Event_Information)
});
2 changes: 1 addition & 1 deletion src/server/routes/users/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export default defineRoute('delete', '/user/:oauthId?', schema, async (req, res)
const {oauthId} = req.params;
await DeleteUser.deleteUser(oauthId);
return res.send(`유저 ${oauthId}를 삭제했습니다.`);
//res.send();

});
14 changes: 14 additions & 0 deletions src/service/event/DeleteEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import User from '../../entity/User';
import Event from '../../entity/Event';

class DeleteEvent {
async deleteEvent(eventId: string): Promise<string> {
const eventIdStr2Num = parseInt(eventId)
await Event.delete({
id: eventIdStr2Num
});
return ;
}
}

export default new DeleteEvent();
25 changes: 25 additions & 0 deletions src/service/event/GetEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import User from '../../entity/User';
import Event from '../../entity/Event';
import Comment from "../../entity/Comment";
import {JoinOptions} from "typeorm/find-options/JoinOptions";
import {number} from "zod";



class GetEvent {
async getEvent(eventId: string): Promise<Event> {
const eventIdStr2Num = parseInt(eventId)
const getEvent = await Event.findOne({where: {id: eventIdStr2Num}});
return getEvent;
}
}

export default new GetEvent();


// 조인 옵션 내일 할게용
// join?: JoinOptions;
//
// innerJoinAndSelect?: {
// [key: string]: string;
// };

0 comments on commit 28a33b8

Please sign in to comment.