Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Fix: 코드 Typescript로 재작성, 상벌점 api 버그
Browse files Browse the repository at this point in the history
  • Loading branch information
leehj050211 committed Apr 29, 2022
1 parent 87bdc26 commit 943b112
Show file tree
Hide file tree
Showing 25 changed files with 365 additions and 204 deletions.
76 changes: 76 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@types/jsonwebtoken": "^8.5.6",
"@types/multer": "^1.4.7",
"@types/request": "^2.48.8",
"@types/web-push": "^3.3.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
Expand All @@ -22,5 +23,10 @@
"ts-node": "^10.4.0",
"typescript": "^4.5.2",
"xss": "^1.0.10"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.3",
"@types/node-schedule": "^1.3.2",
"@types/nodemailer": "^6.4.4"
}
}
5 changes: 3 additions & 2 deletions src/api/school/meister/meister.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BadRequestException, NotFoundException, InternalServerException } from '../../../util/exceptions';
import * as repository from './meister.repository';
import request from 'request'
const http = request.defaults({jar: true});
import iconv from 'iconv-lite';

const getPoint = async (
Expand Down Expand Up @@ -34,7 +35,7 @@ const getPoint = async (
encoding: null,
form:{
caseBy: 'login',
pw: pw,
pw,
lgtype: 'S',
hakgwa: hakgwa,
hak: grade,
Expand Down Expand Up @@ -88,7 +89,7 @@ const getScore = async (

const getHttp = (options: any): Promise<Buffer> => {
return new Promise((resolve, reject) => {
request(options, (err: Error, res: request.Response, body: string) => {
http(options, (err: Error, res: request.Response, body: string) => {
if (err) {
throw new InternalServerException();
}
Expand Down
7 changes: 5 additions & 2 deletions src/api/school/timetable/timetable.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import express from "express"
const router = express.Router();
const service = require('./timetable.service');
import * as service from './timetable.service';

router.get('/timetable/:grade/:classNo', async (req:express.Request, res:express.Response, next:express.NextFunction) => {
try {
res.send(JSON.stringify(
await service.getTimetable(req.params.grade, req.params.classNo)
await service.getTimetable(
Number(req.params.grade),
Number(req.params.classNo)
)
));
} catch(err) {
next(err);
Expand Down
20 changes: 0 additions & 20 deletions src/api/school/timetable/timetable.repository.js

This file was deleted.

39 changes: 39 additions & 0 deletions src/api/school/timetable/timetable.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { InternalServerException } from '../../../util/exceptions';
const pool = require('../../../util/db');

const getTimetable = async (
grade: number,
classNo: number
): Promise<{
monday: string,
tuesday: string,
wednesday: string,
thursday: string,
friday: string
} | null> => {
const getQuery="SELECT monday, tuesday, wednesday, thursday, friday FROM timetable WHERE grade = ? AND classNo = ?"
// SELECT
// monday,
// tuesday,
// wednesday,
// thursday,
// friday
// FROM timetable
// WHERE
// grade = ? AND
// classNo = ?
try {
const [rows] = await pool.query(getQuery, [grade, classNo]);
if (rows.length)
return rows[0];
else
return null;
} catch(err) {
console.error(err);
throw new InternalServerException();
}
}

export {
getTimetable
}
25 changes: 0 additions & 25 deletions src/api/school/timetable/timetable.service.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/api/school/timetable/timetable.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NotFoundException } from '../../../util/exceptions';
import * as repository from './timetable.repository';

const getTimetable = async (
grade: number,
classNo: number
) => {
const timetableInfo = await repository.getTimetable(grade, classNo);
if (timetableInfo === null) {
throw new NotFoundException();
}
const {monday, tuesday, wednesday, thursday, friday} = timetableInfo;
if (monday+tuesday+wednesday+thursday+friday == '') {
throw new NotFoundException();
}
return {
timetable:[
!monday? null: monday.split(','),
!tuesday? null: tuesday.split(','),
!wednesday? null: wednesday.split(','),
!thursday? null: thursday.split(','),
!friday? null: friday.split(','),
]
}
}

export {
getTimetable
}
16 changes: 11 additions & 5 deletions src/api/webpush/push.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import express from "express";
import loginCheck from "../../util/loginCheck";
const router = express.Router();
const service = require('./push.service');
const jwt = require('../../util/jwt')
import * as service from './push.service';
import * as jwt from '../../util/jwt';
import { User } from "../account/User";
import loginCheck from "../../util/loginCheck";

router.post('/meal/register',
loginCheck,
async (req:express.Request, res:express.Response, next:express.NextFunction) => {
const jwtValue = jwt.verify(req.cookies.token);
const user = new User(jwt.verify(req.cookies.token));
try {
res.send(JSON.stringify(
await service.register(req.body.endpoint, req.body.auth, req.body.p256dh, jwtValue.memberCode)
await service.register(
req.body.endpoint,
req.body.auth,
req.body.p256dh,
user
)
));
} catch(err) {
next(err);
Expand Down
39 changes: 0 additions & 39 deletions src/api/webpush/push.repository.js

This file was deleted.

Loading

0 comments on commit 943b112

Please sign in to comment.