Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/controllers/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,16 @@ router.patch(
user.certCodes = certDates.map((c) => c.code);
user.certificationDate = certDates;

user.homeFacility = req.body.homeFacility;

const userOi = await checkOI(user);
if (!userOi) {
throwInternalServerErrorException('Unable to generate operating initials');
}

user.oi = userOi;
} else {
delete user.homeFacility;
}

await user.save();
Expand Down
57 changes: 23 additions & 34 deletions src/controllers/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,41 +438,30 @@ router.post(
}

const positions = eventData.positions;
const positionFields = await Promise.all(
positions.map(async (position: IEventPosition) => {
if (typeof position.takenBy === 'undefined' || position.takenBy === null) {
return {
name: position.pos,
value: 'Open',
inline: true,
};
} else {
try {
const res1 = await UserModel.findOne({ cid: position.takenBy })
.lean()
.cache('10 minutes', `user-${position.takenBy}`)
.exec();
if (!res1) {
throwInternalServerErrorException('User not found');
}

const name = res1.fname + ' ' + res1.lname;
return {
name: position.pos,
value: name,
inline: true,
};
} catch (err) {
console.log(err);
return {
name: position.pos,
value: 'Unknown (Server Error)',
inline: true,
};
}
}
}),
);
const userCids = [...new Set(positions.map((p) => p.takenBy).filter((cid) => !!cid))];
const users = await UserModel.find({ cid: { $in: userCids } })
.lean()
.exec();
const userMap = new Map(users.map((u) => [u.cid, u]));

const positionFields = positions.map((position: IEventPosition) => {
if (!position.takenBy) {
return {
name: position.pos,
value: 'Open',
inline: true,
};
}

const user = userMap.get(position.takenBy);

return {
name: position.pos,
value: user ? `${user.fname} ${user.lname}` : 'Unknown User',
inline: true,
};
});

const fieldsChunked = chunkArray(positionFields, 25); // Chunk into arrays of 25 fields

Expand Down
Loading