Skip to content

Commit c6af832

Browse files
committed
fix: type and date conversion typo in add-option service
1 parent f23dcbd commit c6af832

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

src/server/services/stock-option/add-option.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
import { generatePublicId } from "@/common/id";
2-
import {
3-
type TCreateOptionSchema,
4-
TOptionSchema,
5-
} from "@/server/api/schema/option";
2+
import type { TCreateOptionSchema } from "@/server/api/schema/option";
63
import { Audit } from "@/server/audit";
74
import { db } from "@/server/db";
85
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
6+
import type { TUpdateOption } from "./update-option";
97

10-
interface TAddOption {
11-
companyId: string;
12-
requestIP: string;
13-
userAgent: string;
8+
type AuditPromise = ReturnType<typeof Audit.create>;
9+
10+
type TAddOption = Omit<TUpdateOption, "data" | "optionId"> & {
1411
data: TCreateOptionSchema;
1512
memberId: string;
16-
user: {
17-
id: string;
18-
name: string;
19-
};
20-
}
13+
};
2114

2215
export const addOption = async (payload: TAddOption) => {
2316
try {
2417
const { data, user, memberId } = payload;
2518
const documents = data.documents;
2619

27-
const issuedOption = await db.$transaction(async (tx) => {
20+
const newOption = await db.$transaction(async (tx) => {
2821
const _data = {
2922
grantId: data.grantId,
3023
quantity: data.quantity,
@@ -46,8 +39,7 @@ export const addOption = async (payload: TAddOption) => {
4639

4740
const option = await tx.option.create({ data: _data });
4841

49-
// biome-ignore lint/suspicious/noExplicitAny: <explain>
50-
let auditPromises: any = [];
42+
let auditPromises: AuditPromise[] = [];
5143

5244
if (documents && documents.length > 0) {
5345
const bulkDocuments = documents.map((doc) => ({
@@ -72,53 +64,48 @@ export const addOption = async (payload: TAddOption) => {
7264
actor: { type: "user", id: user.id },
7365
context: {
7466
userAgent: payload.userAgent,
75-
requestIp: payload.requestIP,
67+
requestIp: payload.requestIp,
7668
},
7769
target: [{ type: "document", id: doc.id }],
78-
summary: `${user.name} created a document : ${doc.name}`,
70+
summary: `${user.name} created a document while issuing a stock option : ${doc.name}`,
7971
},
8072
tx,
8173
),
8274
);
8375
}
8476

85-
await Promise.all([
86-
...auditPromises,
77+
auditPromises.push(
8778
Audit.create(
8879
{
8980
action: "option.created",
9081
companyId: payload.companyId,
9182
actor: { type: "user", id: user.id },
9283
context: {
9384
userAgent: payload.userAgent,
94-
requestIp: payload.requestIP,
85+
requestIp: payload.requestIp,
9586
},
9687
target: [{ type: "option", id: option.id }],
9788
summary: `${user.name} issued an option for stakeholder : ${option.stakeholderId}`,
9889
},
9990
tx,
10091
),
101-
]);
92+
);
93+
94+
await Promise.all(auditPromises);
10295

10396
return option;
10497
});
10598

10699
return {
107100
success: true,
108101
message: "🎉 Successfully issued an option.",
109-
data: {
110-
...issuedOption,
111-
issueDate: issuedOption.issueDate.toISOString(),
112-
rule144Date: issuedOption.rule144Date.toISOString(),
113-
vestingStartDate: issuedOption.vestingStartDate.toISOString(),
114-
boardApprovalDate: issuedOption.boardApprovalDate.toISOString(),
115-
expirationDate: issuedOption.expirationDate.toISOString(),
116-
},
102+
data: newOption,
117103
};
118104
} catch (error) {
119105
console.error(error);
120106
if (error instanceof PrismaClientKnownRequestError) {
121107
// Unique constraints error code in prisma
108+
// Only grantId column can throw this error code
122109
if (error.code === "P2002") {
123110
return {
124111
success: false,

0 commit comments

Comments
 (0)