-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathdiscount.ts
More file actions
84 lines (76 loc) · 2.18 KB
/
Copy pathdiscount.ts
File metadata and controls
84 lines (76 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { DiscountProvider, RewardStructure } from "@prisma/client";
import * as z from "zod/v4";
import { getPaginationQuerySchema, maxDurationSchema } from "./misc";
export const DiscountSchema = z.object({
id: z.string(),
amount: z.number(),
type: z.enum(RewardStructure),
maxDuration: z.number().nullable(),
couponId: z.string().nullable(),
couponTestId: z.string().nullable(),
description: z.string().nullish(),
partnersCount: z.number().nullish(),
autoProvisionEnabledAt: z.coerce.date().nullish(),
provider: z.enum(DiscountProvider),
});
export const DiscountSchemaWithDeprecatedFields = DiscountSchema.omit({
autoProvisionEnabledAt: true,
provider: true,
})
.extend({
duration: z
.number()
.nullish()
.describe("Deprecated: Use `maxDuration` instead"),
interval: z.string().nullish().describe("Deprecated: Defaults to `month`"),
})
.nullish();
export const createDiscountSchema = z.object({
workspaceId: z.string(),
amount: z.number().min(0),
type: z.enum(RewardStructure).default("flat"),
maxDuration: maxDurationSchema,
couponId: z.string(),
couponTestId: z.string().nullish(),
groupId: z.string(),
autoProvision: z.boolean().optional(),
provider: z.enum(DiscountProvider),
});
export const updateDiscountSchema = createDiscountSchema
.pick({
workspaceId: true,
couponTestId: true,
autoProvision: true,
})
.extend({
discountId: z.string(),
});
export const discountPartnersQuerySchema = z
.object({
discountId: z.string(),
})
.extend(getPaginationQuerySchema({ pageSize: 25 }));
export const DiscountCodeSchema = z.object({
id: z.string(),
code: z.string(),
discountId: z.string().nullable(),
partnerId: z.string(),
linkId: z.string(),
disabledAt: z.coerce
.date()
.nullish()
.describe(
"When this discount code was disabled, which happens when a partner is banned or deactivated.",
),
});
export const createDiscountCodeSchema = z.object({
code: z
.string()
.max(100, "Code must be less than 100 characters.")
.optional(),
partnerId: z.string(),
linkId: z.string(),
});
export const getDiscountCodesQuerySchema = z.object({
partnerId: z.string(),
});