Skip to content

Merge feature-endpoints into feature-roles - #56

Merged
Flexla54 merged 10 commits into
feature-rolesfrom
feature-endpoints
Jun 3, 2022
Merged

Merge feature-endpoints into feature-roles#56
Flexla54 merged 10 commits into
feature-rolesfrom
feature-endpoints

Conversation

@stephan418

Copy link
Copy Markdown
Collaborator

Adds multiple features to prepare for release

@stephan418 stephan418 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the comments and update the code accordingly

minTeamSize: z.number(),
briefDescription: z.string(),
fullDescription: z.string(),
eventPid: z.string(),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be needed (as the eventPid is in the route, like: /events/:eventPid/disciplines)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in general the code from feature-roles should be used (as this code is more secure). Just leave the parts in that are new here

maxTeamSize: DataType.NUMBER,
briefDescription: DataType.STRING,
["fullDescription?"]: DataType.STRING,
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass the zod error (result.error) as the second parameter to generateInvalidBodyError

},
});

if (!discipline) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has no effect (discipline will always be defined) as prisma.[].update only throws an error if the item to update was not found (PrismaClientKnownRequestError with code P2025)

},
});
}
if (e instanceof Prisma.PrismaClientUnknownRequestError) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is already handled by the server by default, so this is useless code

});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
return res.status(500).json({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, the 404 error should be dispatched here (when the code is P2025)

},
});

if (!updatedRec) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above here: Prisma always returns a model here and throws if the pid could not be found


return res.status(200).json({
type: "success",
payload: {},

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should include some type of payload, was originally only removed because it contained sensitive data

Comment thread src/Controllers/media.controller.ts Outdated
return res.status(204).end();
} catch (e) {
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
console.log("not found error");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log()s and use logger.debug or logger.info for messages that should appear in debug or production respecively

Comment thread src/Controllers/media.controller.ts Outdated
console.log("not found error");
throw new NotFoundError(tableToUpdate[2], pid);
}
if (e instanceof Prisma.PrismaClientUnknownRequestError) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already handled by the default error handler, as above

Comment thread src/Controllers/media.controller.ts Outdated
switch(tableToUpdate) {
case "events": return prisma.event.update;
case "disciplines": return prisma.discipline.update;
default: return prisma.roleSchema.update;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should probably throw some sort of exception and not just assume roleSchema. What if the user passes a string like test as the tableToUpdate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user passes garbage the router won't be called so a 404 will be returned.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that work?

@Stefan-5422 Stefan-5422 mentioned this pull request May 30, 2022
@Flexla54
Flexla54 merged commit 87fa0f3 into feature-roles Jun 3, 2022
@Flexla54
Flexla54 deleted the feature-endpoints branch January 12, 2023 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants