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 createGroups, retrieveAllGroups and assignGroups logics | modify …
…retrieveFiles with shared groups functio | testing HTML and SPECT b00tc4mp#361
- Loading branch information
Showing
33 changed files
with
579 additions
and
46 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
42 changes: 42 additions & 0 deletions
42
staff/abel-prieto/PROYECT/API/handlers/assignGroupsHandler.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,42 @@ | ||
import jwt from 'jsonwebtoken' | ||
import assignGroups from '../logic/assignGroups.js' | ||
import { errors } from 'com' | ||
const { JsonWebTokenError } = jwt | ||
const { NotFoundError, AuthorizationError, ContentError, TokenError, DuplicityError } = errors | ||
|
||
export default async (req, res) => { | ||
const token = req.headers.authorization.substring(7) | ||
const { sub: userId } = jwt.verify(token, process.env.JWT_SECRET) | ||
|
||
const { selectedGroupId, selectedUserId } = req.body | ||
|
||
try { | ||
await assignGroups(userId, selectedUserId, selectedGroupId) | ||
res.status(200).send() | ||
} catch (error) { | ||
let status = 500 | ||
|
||
if (error instanceof AuthorizationError) { | ||
status = 401 | ||
} | ||
|
||
if (error instanceof NotFoundError) { | ||
status = 404 | ||
} | ||
|
||
if (error instanceof DuplicityError) { | ||
status = 406 | ||
} | ||
|
||
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
39 changes: 39 additions & 0 deletions
39
staff/abel-prieto/PROYECT/API/handlers/createGroupHandler.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 createGroup from "../logic/createGroup.js" | ||
import { errors } from 'com' | ||
const { NotFoundError, ContentError, AuthorizationError, TokenError } = errors | ||
const { JsonWebTokenError } = jwt | ||
|
||
export default async (req, res) => { | ||
const token = req.headers.authorization.substring(7) | ||
const { sub: userId } = jwt.verify(token, process.env.JWT_SECRET) | ||
|
||
const { group } = req.body | ||
|
||
try { | ||
await createGroup(userId, group) | ||
res.status(201).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
38 changes: 38 additions & 0 deletions
38
staff/abel-prieto/PROYECT/API/handlers/retrieveAllGroupsHandler.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,38 @@ | ||
import jwt from 'jsonwebtoken' | ||
import retrieveAllGroups from '../logic/retrieveAllGroups.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) | ||
|
||
try { | ||
const allGroups = await retrieveAllGroups(userId) | ||
res.json(allGroups) | ||
|
||
} catch (error) { | ||
let status = 500 | ||
|
||
if (error instanceof NotFoundError) { | ||
status = 404 | ||
} | ||
|
||
if (error instanceof ContentError || error instanceof TypeError) { | ||
status = 409 | ||
} | ||
|
||
if (error instanceof AuthorizationError) { | ||
status = 401 | ||
} | ||
|
||
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
Oops, something went wrong.