47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import type { PrismaClient } from '@generated/prisma/client';
|
|
import type { BillingType, GroupDto, WeekDay } from '@gruperly/shared';
|
|
|
|
export type GroupDb = Pick<PrismaClient, 'group' | 'groupMember' | 'organization'>;
|
|
|
|
type PriceLike = { toString(): string };
|
|
|
|
export type GroupRecord = {
|
|
id: string;
|
|
name: string;
|
|
description: string | null;
|
|
createdById: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
days: WeekDay[] | null;
|
|
time: string | null;
|
|
capacity: number | null;
|
|
price: PriceLike | number | null;
|
|
billingType: BillingType | null;
|
|
dueDay: number | null;
|
|
};
|
|
|
|
export function toGroupDto(record: GroupRecord): GroupDto {
|
|
return {
|
|
id: record.id,
|
|
name: record.name,
|
|
description: record.description,
|
|
createdById: record.createdById,
|
|
createdAt: record.createdAt.toISOString(),
|
|
updatedAt: record.updatedAt.toISOString(),
|
|
days: record.days,
|
|
time: record.time,
|
|
capacity: record.capacity,
|
|
price: record.price == null ? null : Number(record.price.toString()),
|
|
billingType: record.billingType,
|
|
dueDay: record.dueDay,
|
|
};
|
|
}
|
|
|
|
export function buildGroupWhereForUser(userId: string) {
|
|
return {
|
|
OR: [
|
|
{ createdById: userId },
|
|
{ members: { some: { userId } } },
|
|
],
|
|
};
|
|
} |