-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add endpoint to post announcements #180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes, LGTM otherwise
backend/src/config/schema.ts
Outdated
@@ -28,4 +28,5 @@ export const serverSchema = z.object({ | |||
SESSION_MAX_AGE_MS: z.coerce.number().default(86400000), | |||
VITE_FRONTEND_URL: z.string().url().min(1), | |||
VITE_CMS_EXTENSION_ID: z.string().min(1), | |||
CHRONO_SECRET: z.optional(z.string().min(1)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make this optional
@PrimaryGeneratedColumn("uuid") | ||
id!: string; | ||
|
||
@Column({ type: "varchar", length: 800 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a title field as well
export const createAnnoucement = async (req: Request, res: Response) => { | ||
try { | ||
const { chronoSecret, message } = req.body; | ||
|
||
if (env.CHRONO_SECRET !== chronoSecret) { | ||
return res.status(401).json({ message: "Chrono Secret is incorrect" }); | ||
} | ||
|
||
await announcementRepository | ||
.createQueryBuilder() | ||
.insert() | ||
.into(Announcement) | ||
.values({ | ||
message, | ||
}) | ||
.execute(); | ||
|
||
return res | ||
.status(201) | ||
.json({ message: "Announcement Created Successfully" }); | ||
} catch (err) { | ||
return res.status(500).json({ message: "Internal Server Error" }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add title here as well, also move the chronoSecret from the body to the headers of the request instead, since it's used for authentication in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.