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.
create retrieveGuest logic | testing retrieveGuest | create upload file
- Loading branch information
Abel Prieto
committed
Feb 24, 2024
1 parent
067c9df
commit 1a54330
Showing
16 changed files
with
2,640 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import authenticateUserHandler from './authenticateUserHandler.js' | ||
import registerUserHandler from './registerUserHandler.js' | ||
import retrieveUserHandler from './retrieveUserHandler.js' | ||
import retrieveGuestHandler from './retrieveGuestHandler.js' | ||
|
||
export { | ||
authenticateUserHandler, | ||
registerUserHandler, | ||
retrieveUserHandler | ||
retrieveUserHandler, | ||
retrieveGuestHandler | ||
} |
29 changes: 29 additions & 0 deletions
29
staff/abel-prieto/PROYECT/API/handlers/retrieveGuestHandler.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,29 @@ | ||
import retrieveGuest from "../logic/retrieveGuest.js" | ||
import { errors } from 'com' | ||
const { NotFoundError, ContentError } = errors | ||
|
||
export default (req, res) => { | ||
try { | ||
retrieveGuest() | ||
.catch(error => { | ||
let status = 500 | ||
|
||
if (error instanceof NotFoundError) { | ||
status = 404 | ||
} | ||
|
||
res.status(status).json({ error: error.constructor.name, message: error.message }) | ||
|
||
return | ||
}) | ||
.then(guest => res.json(guest)) | ||
} catch (error) { | ||
let status = 500 | ||
|
||
if (error instanceof ContentError || error instanceof TypeError) { | ||
status = 406 | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { User } from "../data/models.js" | ||
import { errors } from "com" | ||
const { SystemError, NotFoundError} = errors | ||
|
||
function retrieveGuest() { | ||
return User.findOne({ email: '[email protected]' }).lean() | ||
.catch(error => { throw new SystemError(error.message)}) | ||
.then(guest => { | ||
if (!guest) { | ||
throw new NotFoundError('Guest not found. Try again') | ||
} | ||
|
||
// USERNAME - TYPE - ROLE | ||
delete guest._id | ||
delete guest.__v | ||
delete guest.email | ||
delete guest.password | ||
|
||
return guest | ||
}) | ||
} | ||
|
||
export default retrieveGuest |
Oops, something went wrong.