lexicongovernance / pluraltools-backend

Backend implementation of the plural voting tool.
https://demo.lexicongovernance.org/
GNU General Public License v3.0
3 stars 1 forks source link

Multiple groups service updates #267

Closed MartinBenediktBusch closed 7 months ago

MartinBenediktBusch commented 7 months ago

This PR includes:

Note that this PR can be tested with our current frontend by providing groups with different groupLabelIds in the groups table.

diegoalzate commented 7 months ago

proposed solution for groups

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;
  }
}