* create seed for org upgrade * migrate about/new pages * pages refactor + use persistant zustand store * invited members view + confirm button * add check to org slug * check reserved subdomain * remove quotes from subdomain env var * intro to creation + billing * create price * fix types * createWithPaymentIntent + permission check on teams * open stripe link in popup * intro to tests * organization price and seat override tests * move permissions to a new permission service * update env and permission check * intro to paid invoice trigger * dont use subId * wip * Get e2e working with migration of teams and members * fix ts errors * Get flow working again * Fix various issues and refactor * Some more fixes * Fix wrong page route link * Platform onboarding fix and moving members of team to org rix * Platform onboarding fix and moving members of team to org rix * Fix tests, found a bug * Get custom price flow working * Get admin impersonation flow working for a non-existent user * Fix unit test * Admin onboarding handover * fix admin onboarding tests * fix ts error * Get updateQuantity working * More fixes * fix test * fix schema name * Add tests * Add missing file * More tests * Add more tests * fix mt-2 moving down input into overflow * fix handover layout removing HOC * Update PR_TODO.md * fix ts error due to merge conflict --------- Co-authored-by: Hariom Balhara <hariombalhara@gmgmail.com> Co-authored-by: Hariom <hariombalhara@gmail.com> Co-authored-by: Omar López <zomars@me.com>
136 lines
3.8 KiB
TypeScript
136 lines
3.8 KiB
TypeScript
import logger from "@calcom/lib/logger";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { BillingPeriod } from "@calcom/prisma/enums";
|
|
|
|
type OnboardingId = string;
|
|
|
|
export type CreateOrganizationOnboardingInput = {
|
|
createdById: number;
|
|
organizationId?: number | null;
|
|
billingPeriod: BillingPeriod;
|
|
pricePerSeat: number;
|
|
seats: number;
|
|
orgOwnerEmail: string;
|
|
name: string;
|
|
slug: string;
|
|
logo?: string | null;
|
|
bio?: string | null;
|
|
stripeCustomerId?: string;
|
|
stripeSubscriptionId?: string;
|
|
stripeSubscriptionItemId?: string;
|
|
invitedMembers?: { email: string; name?: string }[];
|
|
teams?: { id: number; name: string; isBeingMigrated: boolean; slug: string | null }[];
|
|
error?: string | null;
|
|
isDomainConfigured?: boolean;
|
|
};
|
|
|
|
export class OrganizationOnboardingRepository {
|
|
static async create(data: CreateOrganizationOnboardingInput) {
|
|
logger.debug("Creating organization onboarding", safeStringify(data));
|
|
|
|
return await prisma.organizationOnboarding.create({
|
|
// HEKOP
|
|
data: {
|
|
billingPeriod: data.billingPeriod,
|
|
pricePerSeat: data.pricePerSeat,
|
|
seats: data.seats,
|
|
orgOwnerEmail: data.orgOwnerEmail,
|
|
name: data.name,
|
|
slug: data.slug,
|
|
logo: data.logo,
|
|
bio: data.bio,
|
|
stripeCustomerId: data.stripeCustomerId,
|
|
stripeSubscriptionId: data.stripeSubscriptionId,
|
|
invitedMembers: data.invitedMembers || [],
|
|
teams: data.teams || [],
|
|
createdById: data.createdById,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findByStripeCustomerId(stripeCustomerId: string) {
|
|
logger.debug(
|
|
"Finding organization onboarding by stripe customer id",
|
|
safeStringify({ stripeCustomerId })
|
|
);
|
|
return await prisma.organizationOnboarding.findUnique({
|
|
where: {
|
|
stripeCustomerId,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findById(id: OnboardingId) {
|
|
logger.debug("Finding organization onboarding by id", safeStringify({ id }));
|
|
return await prisma.organizationOnboarding.findUnique({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findByOrgOwnerEmail(email: string) {
|
|
logger.debug("Finding organization onboarding by org owner email", safeStringify({ email }));
|
|
return await prisma.organizationOnboarding.findUnique({
|
|
where: {
|
|
orgOwnerEmail: email,
|
|
},
|
|
});
|
|
}
|
|
|
|
// TODO: This method should be moved to OrganizationOnboardingService
|
|
static async markAsComplete(id: OnboardingId) {
|
|
logger.debug("Marking organization onboarding as complete", { id });
|
|
return await prisma.organizationOnboarding.update({
|
|
where: {
|
|
id,
|
|
},
|
|
data: {
|
|
error: null,
|
|
isComplete: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async update(id: OnboardingId, data: Partial<CreateOrganizationOnboardingInput>) {
|
|
logger.debug("Updating organization onboarding", safeStringify({ id, data }));
|
|
|
|
return await prisma.organizationOnboarding.update({
|
|
where: {
|
|
id,
|
|
},
|
|
data: {
|
|
...data,
|
|
updatedAt: new Date(),
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findByOrganizationId(organizationId: number) {
|
|
logger.debug("Finding organization onboarding by organization id", safeStringify({ organizationId }));
|
|
return await prisma.organizationOnboarding.findUnique({
|
|
where: {
|
|
organizationId,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findAllBySlug(slug: string) {
|
|
logger.debug("Finding all organization onboardings by slug", safeStringify({ slug }));
|
|
return await prisma.organizationOnboarding.findMany({
|
|
where: {
|
|
slug,
|
|
},
|
|
});
|
|
}
|
|
static async delete(id: OnboardingId) {
|
|
logger.debug("Deleting organization onboarding", { id });
|
|
return await prisma.organizationOnboarding.delete({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
}
|
|
}
|