From 9e2c6df44f67e12e864e8eed5e93efaf5612526f Mon Sep 17 00:00:00 2001 From: Puru D Date: Sun, 21 Jul 2024 04:23:40 -0500 Subject: [PATCH] fix: build error --- .../migration.sql | 2 ++ prisma/schema.prisma | 2 +- src/server/api/schema/shares.ts | 28 ++++++++++--------- src/server/services/shares/update-share.ts | 10 +++++-- 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 prisma/migrations/20240721090639_default_share_legends/migration.sql diff --git a/prisma/migrations/20240721090639_default_share_legends/migration.sql b/prisma/migrations/20240721090639_default_share_legends/migration.sql new file mode 100644 index 000000000..4139b2dd5 --- /dev/null +++ b/prisma/migrations/20240721090639_default_share_legends/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Share" ALTER COLUMN "companyLegends" SET DEFAULT ARRAY[]::"ShareLegendsEnum"[]; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dfe7f487e..79787279c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -701,7 +701,7 @@ model Share { vestingYears Int @default(0) // 0 means immediate vesting, 1 means vesting over 1 year vestingSchedule VestingScheduleEnum - companyLegends ShareLegendsEnum[] + companyLegends ShareLegendsEnum[] @default([]) issueDate DateTime rule144Date DateTime? diff --git a/src/server/api/schema/shares.ts b/src/server/api/schema/shares.ts index fa7013b70..f7984b18e 100644 --- a/src/server/api/schema/shares.ts +++ b/src/server/api/schema/shares.ts @@ -21,7 +21,7 @@ const SecuritiesStatusArr = Object.values(SecuritiesStatusEnum) as [ export const ShareSchema = z .object({ - id: z.string().cuid().optional().openapi({ + id: z.string().cuid().nullish().openapi({ description: "Share ID", example: "clyvb2s8d0000f1ngd72y2cxw", }), @@ -31,7 +31,7 @@ export const ShareSchema = z example: "DRAFT", }), - certificateId: z.string().optional().openapi({ + certificateId: z.string().nullish().openapi({ description: "Certificate ID", example: "123", }), @@ -41,27 +41,27 @@ export const ShareSchema = z example: 5000, }), - pricePerShare: z.number().nullable().openapi({ + pricePerShare: z.number().nullish().openapi({ description: "Price Per Share", example: 1.25, }), - capitalContribution: z.number().nullable().openapi({ + capitalContribution: z.number().nullish().openapi({ description: "Total amount of money contributed", example: 250000, }), - ipContribution: z.number().nullable().openapi({ + ipContribution: z.number().nullish().openapi({ description: "Value of the intellectual property contributed", example: 0, }), - debtCancelled: z.number().nullable().openapi({ + debtCancelled: z.number().nullish().openapi({ description: "Amount of debt cancelled", example: 0, }), - otherContributions: z.number().nullable().openapi({ + otherContributions: z.number().nullish().openapi({ description: "Other contributions", example: 0, }), @@ -74,27 +74,29 @@ export const ShareSchema = z companyLegends: z .enum(ShareLegendsArr) .array() + .default([]) + .nullish() .openapi({ description: "Company Legends", example: ["US_SECURITIES_ACT", "SALE_AND_ROFR"], }), - issueDate: z.string().datetime().openapi({ + issueDate: z.string().datetime().nullish().openapi({ description: "Issued Date", example: "2024-01-01T00:00:00.000Z", }), - rule144Date: z.string().datetime().nullable().openapi({ + rule144Date: z.string().datetime().nullish().openapi({ description: "Rule 144 Date", example: "2024-01-01T00:00:00.000Z", }), - vestingStartDate: z.string().datetime().nullable().openapi({ + vestingStartDate: z.string().datetime().nullish().openapi({ description: "Vesting Start Date", example: "2024-01-01T00:00:00.000Z", }), - boardApprovalDate: z.string().datetime().optional().openapi({ + boardApprovalDate: z.string().datetime().nullish().openapi({ description: "Board Approval Date", example: "2024-01-01T00:00:00.000Z", }), @@ -114,12 +116,12 @@ export const ShareSchema = z example: "clyvb2d8v0000f1ng1stpa38s", }), - createdAt: z.string().datetime().optional().openapi({ + createdAt: z.string().datetime().nullish().openapi({ description: "Share Created at", example: "2024-01-01T00:00:00.000Z", }), - updatedAt: z.string().datetime().optional().openapi({ + updatedAt: z.string().datetime().nullish().openapi({ description: "Share Updated at", example: "2024-01-01T00:00:00.000Z", }), diff --git a/src/server/services/shares/update-share.ts b/src/server/services/shares/update-share.ts index 673078374..4d7ca7cc4 100644 --- a/src/server/services/shares/update-share.ts +++ b/src/server/services/shares/update-share.ts @@ -2,6 +2,7 @@ import { ApiError } from "@/server/api/error"; import type { UpdateShareSchemaType } from "@/server/api/schema/shares"; import { Audit } from "@/server/audit"; import { db } from "@/server/db"; +import type { ShareLegendsEnum } from "@prisma/client"; export type UpdateSharePayloadType = { shareId: string; @@ -30,11 +31,16 @@ export const updateShare = async (payload: UpdateSharePayloadType) => { }; } - console.log({ data }); + const shareData = { + ...existingShare, + ...data, + }; + const share = await db.$transaction(async (tx) => { const share = await tx.share.update({ where: { id: shareId }, - data, + // @ts-ignore + data: shareData, }); await Audit.create(