Files
zooqueen fb4e3df0e3 rename: @hanzo/sign-* → @hanzo/esign-* (full eSign brand consistency)
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign).
Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files)
and align docker/Dockerfile turbo --scope/--filter to the actual remix
package name @hanzo/esign (was a pre-existing mismatch with -remix that
broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
2026-06-21 19:56:09 -07:00

90 lines
2.0 KiB
TypeScript

import type { OrganisationMemberRole, OrganisationType } from '@prisma/client';
import { OrganisationGroupType, type User } from '@prisma/client';
import { hashSync } from '@hanzo/esign-lib/server-only/auth/hash';
import { addUserToOrganisation } from '@hanzo/esign-lib/server-only/organisation/accept-organisation-invitation';
import { prisma } from '..';
import { seedTestEmail } from './users';
export const seedOrganisationMembers = async ({
members,
organisationId,
}: {
members: {
email?: string;
name?: string;
organisationRole: OrganisationMemberRole;
}[];
organisationId: string;
}) => {
const membersToInvite: {
email: string;
organisationRole: OrganisationMemberRole;
}[] = [];
const createdMembers: User[] = [];
const organisationGroups = await prisma.organisationGroup.findMany({
where: {
organisationId,
type: OrganisationGroupType.INTERNAL_ORGANISATION,
},
});
for (const member of members) {
const email = member.email ?? seedTestEmail();
let newUser = await prisma.user.findFirst({
where: {
email: email.toLowerCase(),
},
});
if (!newUser) {
newUser = await prisma.user.create({
data: {
name: member.name ?? 'Test user',
email: email.toLowerCase(),
password: hashSync('password'),
emailVerified: new Date(),
},
});
}
createdMembers.push(newUser);
membersToInvite.push({
email: newUser.email,
organisationRole: member.organisationRole,
});
await addUserToOrganisation({
userId: newUser.id,
organisationId,
organisationGroups,
organisationMemberRole: member.organisationRole,
bypassEmail: true,
});
}
return createdMembers;
};
export const setOrganisationType = async ({
organisationId,
type,
}: {
organisationId: string;
type: OrganisationType;
}) => {
await prisma.organisation.update({
where: {
id: organisationId,
},
data: {
type,
},
});
};