Andrew Valleteau
03/08/2022, 9:45 AM// IN POSTGRESQL
type permission_type (entity_id uuid, access text);
update_permissions(target_id uuid, new_permissions permission_type[])
// In Typescript
const entityId = 'abc-def-hij'
const newPerms = [{id: 'abc-def-hig', access: 'write'}];
await prisma.$executeRaw(`SELECT update_permission(${entityId}, array[${Prisma.join(newPerms.map((p) => `(${p.id}, ${p.access})`)}]::permission_type[]))`);
Would that be correct ?Andrew Valleteau
03/08/2022, 10:30 AMAndrew Valleteau
03/08/2022, 10:44 AMAndrew Valleteau
03/08/2022, 10:44 AMconst preparedOrgsPerms = props.orgs.map(
(perm) => `('${perm.id}', '${perm.access}')::permission_type`
);
const preparedTeamsPerms = props.teams.map(
(perm) => `('${perm.id}, '${perm.access}')::permission_type`
);
const preparedUsersPerms = props.users.map(
(perm) => `('${perm.id}', '${perm.access}')::permission_type`
);
await prisma.$executeRaw`
SELECT update_folder_permissions(
${projectId},
${parentId},
${props.folderId},
array[${Prisma.join(preparedOrgsPerms)}]::permission_type[],
array[${Prisma.join(preparedTeamsPerms)}]::permission_type[],
array[${Prisma.join(preparedUsersPerms)}]::permission_type[]
);
`;
janpio