-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix:Runtime error & Add:single participant (#546)
* added markdown editor with save feature * basic Emailer integration done * feat: added user registration page (registration-admin) (#507) * trial push * added button * modal added * added modal form fields * removed unnecessary code * added chakra-ui * form field display (error not fixed) * feat: Added participand routes and hooks for registration-admin * Did something * proper post reuest set * feat: added route for participant form submission in registration-admin * registration completed * Registration complete page added * added cookie to check registration * added endOfLine to prettier * removed eol from prettier --------- Co-authored-by: aaron-6960 <[email protected]> Co-authored-by: aaron-6960 <[email protected]> Co-authored-by: Subramani E <[email protected]> * Build issues fixed * Fix:Runtime error solved --------- Co-authored-by: Subramani E <[email protected]> Co-authored-by: Midhun Unni <[email protected]> Co-authored-by: aaron-6960 <[email protected]> Co-authored-by: aaron-6960 <[email protected]> Co-authored-by: Subramani E <[email protected]>
- Loading branch information
1 parent
e56a6ef
commit d3ef109
Showing
39 changed files
with
2,628 additions
and
16,432 deletions.
There are no files selected for viewing
Empty file.
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,107 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
import prisma from '../utils/database'; | ||
|
||
export const orgAndEventVerification = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
|
||
const event = await prisma.event.findFirst({ | ||
where: { | ||
id: eventId, | ||
}, | ||
}); | ||
if (!event) { | ||
return res.status(404).json({ error: 'Event not found' }); | ||
} | ||
if (event.organizationId != orgId) { | ||
return res.status(404).json({ error: "Organisation and event don't match" }); | ||
} | ||
return res.status(200).json({ msg: 'Event corresponds to the given org and both exists' }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const addFormResponse = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
const data = req?.body; | ||
|
||
const defaultKeys = ['firstName', 'lastName', 'email', 'phone']; | ||
const defaultData: { [key: string]: string } = {}; | ||
const attrData: { attributeId: string; value: string }[] = []; | ||
|
||
for (const key in data) { | ||
if (defaultKeys.includes(key)) { | ||
defaultData[key] = data[key]; | ||
} else { | ||
attrData.push({ | ||
attributeId: key, | ||
value: data[key], | ||
}); | ||
} | ||
} | ||
|
||
const newRegistrant = await prisma.registrant.create({ | ||
data: { | ||
firstName: defaultData['firstName'], | ||
lastName: defaultData['lastName'] || null, | ||
email: defaultData['email'], | ||
phone: defaultData['phone'] || null, | ||
eventId: eventId, | ||
organizationId: orgId, | ||
registrantAttributes: { | ||
create: attrData, | ||
}, | ||
}, | ||
}); | ||
|
||
return res.status(200).json({ newRegistrant }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const getFormAttributes = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
|
||
let ExtraAttributes = await prisma.attributes.findMany({ | ||
where: { | ||
organizationId: orgId, | ||
eventId: eventId, | ||
}, | ||
include: { | ||
participantAttributes: true, | ||
}, | ||
}); | ||
|
||
const defaultAttributes = [ | ||
{ name: 'First Name', id: 'firstName' }, | ||
{ name: 'Last Name', id: 'lastName' }, | ||
{ name: 'Email', id: 'email' }, | ||
{ name: 'Phone Number', id: 'phone' }, | ||
]; | ||
|
||
ExtraAttributes = ExtraAttributes.map((attribute: any) => { | ||
return { | ||
name: attribute.name, | ||
id: attribute.id, | ||
}; | ||
}); | ||
|
||
const attributes = defaultAttributes.concat(ExtraAttributes); | ||
|
||
if (!attributes) { | ||
return res.status(404).json({ error: 'No attributes found' }); | ||
} | ||
|
||
return res.status(200).json({ attributes }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; |
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 express, { Router } from 'express'; | ||
import { | ||
orgAndEventVerification, | ||
getFormAttributes, | ||
addFormResponse, | ||
} from './controllers/registration'; | ||
|
||
const router: Router = express.Router(); | ||
|
||
router.get('/', (req: any, res: any) => { | ||
try { | ||
return res.send('Hello World!'); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(500); | ||
} | ||
}); | ||
|
||
router.get('/:orgId/event/:eventId/verify', orgAndEventVerification); | ||
router.get('/:orgId/event/:eventId/attributes', getFormAttributes); | ||
router.post('/:orgId/event/:eventId/submit', addFormResponse); | ||
|
||
export default router; |
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.