diff --git a/package-lock.json b/package-lock.json index ff61038..a876363 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "BSM", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "BSM", - "version": "1.4.1", + "version": "1.5.0", "dependencies": { "@types/express": "^4.17.13", "@types/jsonwebtoken": "^8.5.8", diff --git a/package.json b/package.json index 87fcf98..01efc42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "BSM", - "version": "1.4.1", + "version": "1.5.0", "scripts": { "start": "node dist/main.js", "prestart": "tsc && babel dist -d dist" diff --git a/src/api/oauth/oauth.controller.ts b/src/api/oauth/oauth.controller.ts index b278524..c3ca018 100644 --- a/src/api/oauth/oauth.controller.ts +++ b/src/api/oauth/oauth.controller.ts @@ -81,6 +81,20 @@ router.post('/client', loginCheck, async (req: express.Request, res: express.Res } }) +router.delete('/client/:clientId', loginCheck, async (req: express.Request, res: express.Response, next: express.NextFunction) => { + const user = new User(jwt.verify(req.cookies.token).value); + try { + res.send(JSON.stringify( + await service.deleteClient( + req.params.clientId, + user + ) + )); + } catch(err) { + next(err); + } +}) + router.get('/client', loginCheck, async (req: express.Request, res: express.Response, next: express.NextFunction) => { const user = new User(jwt.verify(req.cookies.token).value); try { diff --git a/src/api/oauth/oauth.service.ts b/src/api/oauth/oauth.service.ts index 823a182..404acea 100644 --- a/src/api/oauth/oauth.service.ts +++ b/src/api/oauth/oauth.service.ts @@ -221,6 +221,17 @@ const uriCheck = (domain: string, str: string): boolean => { return pattern.test(str); } +const deleteClient = async ( + clientId: string, + user: User +) => { + const clientInfo = await oauthClientReposiroty.getById(clientId); + if (clientInfo === null || clientInfo.usercode != user.getUser().code) { + throw new BadRequestException(); + } + await oauthClientReposiroty.deleteClient(clientId); +} + const getClientList = async ( user: User ) => { @@ -272,6 +283,7 @@ export { getToken, getResource, createClient, + deleteClient, getClientList, getScopeInfo } \ No newline at end of file diff --git a/src/api/oauth/repository/client.repository.ts b/src/api/oauth/repository/client.repository.ts index 5d714d1..e3ad4ea 100644 --- a/src/api/oauth/repository/client.repository.ts +++ b/src/api/oauth/repository/client.repository.ts @@ -86,8 +86,23 @@ const createClient = async ( } } +const deleteClient = async ( + clientId: string +): Promise => { + const deleteQuery='DELETE FROM oauth_client WHERE client_id=?'; + // DELETE FROM oauth_client + // WHERE client_id=? + try { + await pool.query(deleteQuery, [clientId]); + } catch(err) { + console.error(err); + throw new InternalServerException(); + } +} + export { getById, getByUsercode, - createClient + createClient, + deleteClient } \ No newline at end of file diff --git a/src/api/version/version.service.ts b/src/api/version/version.service.ts index 55763fe..c0bc8ce 100644 --- a/src/api/version/version.service.ts +++ b/src/api/version/version.service.ts @@ -7,8 +7,8 @@ const getVersion = ( switch (isApp) { case 'web': return { - versionCode: 5, - versionName: '1.4.1' + versionCode: 6, + versionName: '1.5.0' } case 'app': switch (os) {