forked from b00tc4mp/isdi-parttime-202309
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deleteGroup logic with HTML and SPECT testing | refactor handlers…
… with ASYNC-AWAIT b00tc4mp#361
- Loading branch information
Showing
24 changed files
with
395 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
staff/abel-prieto/PROYECT/API/handlers/deleteGroupHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import jwt from 'jsonwebtoken' | ||
import deleteGroup from '../logic/deleteGroup.js' | ||
import { errors } from 'com' | ||
const { JsonWebTokenError } = jwt | ||
const { NotFoundError, AuthorizationError, TokenError, ContentError } = errors | ||
|
||
export default async (req, res) => { | ||
const token = req.headers.authorization.substring(7) | ||
const { sub: userId } = jwt.verify(token, process.env.JWT_SECRET) | ||
|
||
const { groupId } = req.params | ||
|
||
try { | ||
await deleteGroup(userId, groupId) | ||
res.status(200).send() | ||
|
||
} catch (error) { | ||
let status = 500 | ||
|
||
if (error instanceof AuthorizationError) { | ||
status = 401 | ||
} | ||
|
||
if (error instanceof NotFoundError) { | ||
status = 404 | ||
} | ||
|
||
if (error instanceof TypeError || error instanceof ContentError) { | ||
status = 409 | ||
} | ||
|
||
if (error instanceof JsonWebTokenError) { | ||
status = 401 | ||
error = new TokenError(error.message) | ||
} | ||
|
||
res.status(status).json({ error: error.constructor.name, message: error.message }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.