Skip to content

Commit

Permalink
feat: Mega UI UX update MVP (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
alllenshibu authored Feb 23, 2024
1 parent ee28acf commit 5c29b51
Show file tree
Hide file tree
Showing 21 changed files with 1,092 additions and 1,123 deletions.
34 changes: 32 additions & 2 deletions apps/core-admin/src/controllers/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ export const getAllAttributes = async (req: Request, res: Response) => {
try {
const { orgId, eventId } = req?.params;

const attributes = await prisma.attributes.findMany({
let attributes = await prisma.attributes.findMany({
where: {
organizationId: orgId,
eventId: eventId,
},
include: {
participantAttributes: true,
},
});

attributes = attributes.map((attribute: any) => {
return {
id: attribute.id,
name: attribute.name,
createdAt: attribute.createdAt,
numberOfParticipantsWithAttributeAssigned: attribute.participantAttributes.length,
};
});

if (!attributes) {
Expand All @@ -28,7 +40,7 @@ export const getAttributeById = async (req: Request, res: Response) => {
try {
const { orgId, eventId, attributeId } = req?.params;

const attribute = await prisma.attributes.findFirst({
let attribute = await prisma.attributes.findFirst({
where: {
organizationId: orgId,
eventId,
Expand All @@ -47,6 +59,24 @@ export const getAttributeById = async (req: Request, res: Response) => {
return res.status(404).json({ error: 'No attributes found' });
}

attribute = {
id: attribute.id,
name: attribute.name,
createdAt: attribute.createdAt,
numberOfParticipantsWithAttributeAssigned: attribute.participantAttributes.length,
participantAttributeDetails: attribute.participantAttributes.map(
(participantAttribute: any) => {
return {
id: participantAttribute.id,
value: participantAttribute.value,
addedAt: participantAttribute.createdAt,
firstName: participantAttribute.participant.firstName,
lastName: participantAttribute.participant.lastName,
};
},
),
};

return res.status(200).json({ attribute });
} catch (err: any) {
console.error(err);
Expand Down
70 changes: 69 additions & 1 deletion apps/core-admin/src/controllers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,27 @@ export const getEvents = async (req: Request, res: Response) => {
return res.status(403).json({ error: 'Forbidden' });
}

const events = await prisma.event.findMany({
let events = await prisma.event.findMany({
where: {
organizationId: orgId,
},
include: {
Participant: true,
attributes: true,
ParticipantCheckin: true,
},
});

events = events.map((event: any) => {
return {
id: event.id,
name: event.name,
description: event.description,
createdAt: event.createdAt,
numberOfParticipants: event.Participant.length,
numberOfAttributes: event.attributes.length,
numberOfParticipantsCheckedIn: event.ParticipantCheckin.length,
};
});

return res.status(200).json({ events });
Expand All @@ -34,6 +51,57 @@ export const getEvents = async (req: Request, res: Response) => {
}
};

export const getEventStats = async (req: Request, res: Response) => {
try {
const userId = req?.auth?.payload?.sub;
const { orgId, eventId } = req?.params;

const organization = await prisma.organization.findUnique({
where: {
id: orgId,
},
});

if (!organization) {
return res.status(404).json({ error: 'Organization not found' });
}

if (organization?.organizationUsers?.some((ou: any) => ou.userId === userId)) {
return res.status(403).json({ error: 'Forbidden' });
}

let event = await prisma.event.findUnique({
where: {
id: eventId,
},
include: {
Participant: true,
attributes: true,
ParticipantCheckin: true,
},
});

if (!event) {
return res.status(404).json({ error: 'Event not found' });
}

event = {
id: event.id,
name: event.name,
description: event.description,
createdAt: event.createdAt,
numberOfParticipants: event.Participant.length,
numberOfAttributes: event.attributes.length,
numberOfParticipantsCheckedIn: event.ParticipantCheckin.length,
};

return res.status(200).json({ event });
} catch (err: any) {
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
}
};

export const createNewEvent = async (req: Request, res: Response) => {
try {
const userId = req?.auth?.payload?.sub;
Expand Down
Loading

0 comments on commit 5c29b51

Please sign in to comment.