Closed MartinBenediktBusch closed 7 months ago
export async function upsertUsersToGroups(
dbPool: PostgresJsDatabase<typeof db>,
userId: string,
newGroupIds: string[],
): Promise<db.UsersToGroups[] | null> {
try {
// assume the groupLabelId is in user_to_groups
// query groups to get groupLabelId
const groups = await dbPool.groups.findMany({ where: { id: { in: newGroupIds } } });
// STEP 1
// changes to user-groups without groupLabelId
// same as logic as before as they are probably affiliations
// check if it exists
// i.e update
// i.e insert
// STEP 2
// changes to user-groups with groupLabelId (groups that are meant for event participation)
// i.e update all user to groups that we found have groupLabelId and userId
// i.e insert all user to groups that we found have groupLabelId and userId
} catch (error) {
console.error('Error upserting user groups: ' + JSON.stringify(error));
return null;
}
}
This PR includes:
users.ts
service to expose theupsertUsersToGroups
function in order to make it easier to test.groupLabelId
tousersToGroups
table as it is necessary for updating the table based on auserId
andgroupLabelId
combinationusersToGroups
service to allow that theusersToGroups
table can store multipleuser-group
relationshipsseed
for easier testinguserToGroup.specs
groupLabelId
Note that this PR can be tested with our current frontend by providing groups with different
groupLabelIds
in thegroups
table.