-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: vercel prod * fix: ses removed * fix: app login return events * fix: user_email added for get users for a event * fix: get users api * fix: updated get users in params * feat: event creation * fix: update api * fix: 🐻 amazon ses added
- Loading branch information
1 parent
85b2775
commit b24be2f
Showing
11 changed files
with
63 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,53 @@ | ||
import { Response, Request } from "express"; | ||
import { pool } from "../../config/db.js"; | ||
import { Events, EventsHome } from "../interfaces/eventInterface.js"; | ||
import { | ||
createEvent, | ||
deleteEvent, | ||
getAllEvents, | ||
getEventDetails, | ||
updateEvent, | ||
editEvent | ||
} from "../queries/eventQueries.js"; | ||
import { EventIdValidator } from "../validators/eventValidators.js"; | ||
const eventProperties = [ | ||
"name", | ||
"description", | ||
"tag_line", | ||
"rules", | ||
"img_link", | ||
"fee", | ||
"date", | ||
"team_size", | ||
"youtube", | ||
"instagram", | ||
"first_prize", | ||
"second_prize", | ||
"third_prize", | ||
"is_paid", | ||
]; | ||
|
||
const GetAllEvents = async (_: Request, res: Response) => { | ||
const client = await pool.connect(); | ||
const result = await client.query(getAllEvents); | ||
const events: Array<EventsHome> = result.rows; | ||
client.release(); | ||
|
||
return res | ||
.status(200) | ||
.json({ status: 200, body: { message: "Sucessfull", events } }); | ||
}; | ||
|
||
const GetSpecificEvent = async (req: Request, res: Response) => { | ||
const id = EventIdValidator.parse(req.params.id); | ||
const client = await pool.connect(); | ||
const result = await client.query(getEventDetails, [id]); | ||
const events: Array<Events> = result.rows; | ||
client.release(); | ||
|
||
return res | ||
.status(200) | ||
.send({ status: 200, body: { message: "Sucessfull", events } }); | ||
}; | ||
|
||
const CreateEvent = async (req: Request, res: Response) => { | ||
const client = await pool.connect(); | ||
const eventData = req.body; | ||
const sql_arr = eventProperties.map((prop) => eventData[prop]); | ||
if (eventData.name) { | ||
await client.query(createEvent, sql_arr).then(() => { | ||
client.release(); | ||
}); | ||
|
||
if(req.body.admin.is_super_admin){ | ||
const { event_id, name, fee, pass_id} = req.body | ||
const client = await pool.connect() | ||
await client.query(createEvent, [event_id, name, fee, pass_id]) | ||
client.release() | ||
return res | ||
.status(200) | ||
.json({ status: 200, body: { message: "Sucessfull" } }); | ||
} else | ||
}else | ||
return res | ||
.status(400) | ||
.json({ status: 400, body: { message: "BadRequest" } }); | ||
}; | ||
|
||
const DeleteEvent = async (req: Request, res: Response) => { | ||
const id = EventIdValidator.parse(req.params.id); | ||
if (id) { | ||
const client = await pool.connect(); | ||
await client.query(deleteEvent, [id]).then(() => { | ||
client.release(); | ||
}); | ||
return res | ||
.status(200) | ||
.json({ status: 200, body: { message: "Sucessfull" } }); | ||
} else | ||
return res | ||
.status(400) | ||
.json({ status: 400, body: { message: "BadRequest" } }); | ||
.status(403) | ||
.json({ status: 403, body: { message: "Not Authorized" } }); | ||
}; | ||
|
||
const UpdateEvent = async (req: Request, res: Response) => { | ||
const id = EventIdValidator.parse(req.params.id); | ||
const client = await pool.connect(); | ||
const eventData = { ...req.body }; | ||
const sql_arr = eventProperties.map((props) => eventData[props]); | ||
if (id) { | ||
await client.query(updateEvent, [...sql_arr, id]); | ||
client.release(); | ||
|
||
return res | ||
.status(200) | ||
.json({ status: 200, body: { message: "Sucessfull" } }); | ||
} else | ||
if(req.body.admin.is_super_admin || (req.body.admin.events_id.includes(req.body.event_id))){ | ||
try{ | ||
const { event_id, name, fee, pass_id} = req.body | ||
const client = await pool.connect() | ||
const data = await client.query(editEvent, [event_id, name, fee, pass_id]) | ||
client.release() | ||
if(data.rows.length == 1) | ||
return res | ||
.status(200) | ||
.json({ status: 200, body: { message: "Updated Sucessfull" } }); | ||
else | ||
return res | ||
.status(500) | ||
.json({ status: 500, body: { message: "Event doesnot exist" } }); | ||
} catch(err){ | ||
console.log(err) | ||
return res | ||
.status(500) | ||
.json({ status: 500, body: { message: "Event not updated" } }); | ||
} | ||
}else | ||
return res | ||
.status(400) | ||
.json({ status: 400, body: { message: "BadRequest" } }); | ||
.status(403) | ||
.json({ status: 403, body: { message: "Not Authorized" } }); | ||
}; | ||
|
||
export { | ||
CreateEvent, | ||
DeleteEvent, | ||
GetAllEvents, | ||
GetSpecificEvent, | ||
UpdateEvent, | ||
UpdateEvent | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,7 @@ | ||
export const getAllEvents: string = ` | ||
SELECT | ||
event_id, | ||
name, | ||
img_link, | ||
tag_line, | ||
date, | ||
description | ||
FROM events`; | ||
export const getEventDetails: string = ` | ||
SELECT | ||
e.event_id, | ||
e.name AS event_name, | ||
e.description, | ||
e.tag_line, | ||
e.rules, | ||
e.img_link, | ||
e.fee, | ||
e.team_size, | ||
e.date, | ||
e.youtube, | ||
e.instagram, | ||
e.first_prize, | ||
e.second_prize, | ||
e.third_prize, | ||
i.name AS incharge_name, | ||
i.id AS incharge_id, | ||
i.phone_no | ||
FROM | ||
events e | ||
LEFT JOIN | ||
incharge_event ie ON e.event_id = ie.event_id | ||
LEFT JOIN | ||
incharges i ON i.id = ie.incharge_id | ||
WHERE | ||
e.event_id = $1; | ||
`; | ||
export const createEvent: string = `INSERT INTO | ||
events (name, description, tag_line, rules, img_link, fee, date, team_size, youtube, instagram, first_prize, second_prize, third_prize, is_paid) | ||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`; | ||
export const deleteEvent: string = "DELETE FROM events WHERE event_id=$1"; | ||
export const updateEvent: string = `UPDATE events SET | ||
name = $1, | ||
description = $2, | ||
tag_line = $3, | ||
rules = $4, | ||
img_link = $5, | ||
fee = $6, | ||
date = $7, | ||
team_size = $8, | ||
youtube = $9, | ||
instagram = $10, | ||
first_prize = $11, | ||
second_prize = $12, | ||
third_prize = $13, | ||
is_paid = $14 | ||
WHERE event_id=$15`; | ||
events (id, name, fee, pass_id) VALUES ($1, $2, $3, $4)`; | ||
export const editEvent: string = `UPDATE events SET | ||
name = $2, | ||
fee = $3, | ||
pass_id = $4 | ||
WHERE id = $1 returning *`; |
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