@mac777/project-pinecone-schema 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/events/events.constants.d.ts +1 -8
- package/dist/events/events.constants.js +1 -6
- package/dist/events/events.schema.d.ts +110 -55
- package/dist/events/events.type.d.ts +0 -8
- package/dist/events/utils/ticket.schema.d.ts +6 -3
- package/dist/events/utils/ticket.schema.js +2 -1
- package/package.json +2 -5
- package/src/auth/auth.constants.ts +9 -0
- package/src/auth/auth.schema.ts +65 -0
- package/src/auth/auth.type.ts +42 -0
- package/src/auth/index.ts +3 -0
- package/src/auth/utils/password.schema.ts +18 -0
- package/src/events/events.constants.ts +170 -0
- package/src/events/events.schema.ts +158 -0
- package/src/events/events.type.ts +51 -0
- package/src/events/events.utils.schema.ts +5 -0
- package/{dist/events/events.d.ts → src/events/index.ts} +4 -3
- package/src/events/utils/admin.schema.ts +77 -0
- package/src/events/utils/age.restriction.schema.ts +3 -0
- package/src/events/utils/document.schema.ts +8 -0
- package/src/events/utils/event.type.schema.ts +3 -0
- package/src/events/utils/media.schema.ts +36 -0
- package/src/events/utils/organizer.schema.ts +14 -0
- package/src/events/utils/schedule.schema.ts +10 -0
- package/src/events/utils/ticket.schema.ts +33 -0
- package/src/events/utils/venue.schema.ts +22 -0
- package/src/index.ts +5 -0
- package/src/media/index.ts +2 -0
- package/src/media/media.schema.ts +37 -0
- package/src/media/media.type.ts +18 -0
- package/src/media/utils/backblaze.schema.ts +8 -0
- package/src/media/utils/imagekit.schema.ts +20 -0
- package/src/orders/index.ts +6 -0
- package/src/orders/orders.schema.ts +106 -0
- package/src/orders/orders.type.ts +85 -0
- package/src/orders/payments.schema.ts +81 -0
- package/src/orders/payments.type.ts +87 -0
- package/src/orders/ticket.schema.ts +78 -0
- package/src/orders/ticket.type.ts +103 -0
- package/tsconfig.json +13 -0
- package/dist/auth.d.ts +0 -1
- package/dist/auth.js +0 -18
- package/dist/events/admin.schema.d.ts +0 -208
- package/dist/events/admin.schema.js +0 -70
- package/dist/events/age.restriction.schema.d.ts +0 -2
- package/dist/events/age.restriction.schema.js +0 -5
- package/dist/events/document.schema.d.ts +0 -17
- package/dist/events/document.schema.js +0 -10
- package/dist/events/event.schema.d.ts +0 -0
- package/dist/events/event.schema.js +0 -1
- package/dist/events/event.type.schema.d.ts +0 -2
- package/dist/events/event.type.schema.js +0 -5
- package/dist/events/events.constant.d.ts +0 -9
- package/dist/events/events.constant.js +0 -12
- package/dist/events/events.js +0 -19
- package/dist/events/media.schema.d.ts +0 -77
- package/dist/events/media.schema.js +0 -36
- package/dist/events/organizer.schema.d.ts +0 -55
- package/dist/events/organizer.schema.js +0 -15
- package/dist/events/schedule.schema.d.ts +0 -20
- package/dist/events/schedule.schema.js +0 -11
- package/dist/events/step.schema.d.ts +0 -0
- package/dist/events/step.schema.js +0 -1
- package/dist/events/ticket.schema.d.ts +0 -113
- package/dist/events/ticket.schema.js +0 -29
- package/dist/events/utils.schema.d.ts +0 -6
- package/dist/events/utils.schema.js +0 -22
- package/dist/events/venue.schema.d.ts +0 -75
- package/dist/events/venue.schema.js +0 -22
- package/dist/events.constant.d.ts +0 -9
- package/dist/events.constant.js +0 -12
- package/dist/events.constants.d.ts +0 -9
- package/dist/events.constants.js +0 -12
- package/dist/events.d.ts +0 -39
- package/dist/events.js +0 -2
- package/dist/events.schema.d.ts +0 -229
- package/dist/events.schema.js +0 -95
- package/dist/events.type.d.ts +0 -42
- package/dist/events.type.js +0 -2
- package/dist/events.utils.schema.d.ts +0 -6
- package/dist/events.utils.schema.js +0 -22
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Metrics schema
|
|
4
|
+
export const metricsSchema = z.object({
|
|
5
|
+
views: z.number({ required_error: 'Views must be a number' }).int('Views must be an integer').min(0, 'Views cannot be negative').default(0),
|
|
6
|
+
ticketsSold: z.number({ required_error: 'Tickets sold must be a number' }).int('Tickets sold must be an integer').min(0, 'Tickets sold cannot be negative').default(0),
|
|
7
|
+
revenue: z.number({ required_error: 'Revenue must be a number' }).min(0, 'Revenue cannot be negative').default(0),
|
|
8
|
+
checkIns: z.number({ required_error: 'Check-ins must be a number' }).int('Check-ins must be an integer').min(0, 'Check-ins cannot be negative').default(0),
|
|
9
|
+
averageRating: z.number().min(0, 'Rating must be at least 0').max(5, 'Rating cannot exceed 5').optional(),
|
|
10
|
+
reviewCount: z.number({ required_error: 'Review count must be a number' }).int('Review count must be an integer').min(0, 'Review count cannot be negative').default(0),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Business schemas
|
|
14
|
+
export const pricingSchema = z.object({
|
|
15
|
+
platformFee: z.number({ required_error: 'Platform fee must be a number' }).min(0, 'Platform fee cannot be negative').default(5),
|
|
16
|
+
paymentProcessingFee: z.number().min(0, 'Payment processing fee cannot be negative').optional(),
|
|
17
|
+
currency: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const payoutSchema = z.object({
|
|
21
|
+
status: z.enum(['pending', 'scheduled', 'completed'], { required_error: 'Payout status must be pending, scheduled, or completed' }).optional(),
|
|
22
|
+
amount: z.number().min(0, 'Payout amount cannot be negative').optional(),
|
|
23
|
+
scheduledDate: z.string().datetime('Payout scheduled date must be a valid ISO datetime string').optional(),
|
|
24
|
+
paidAt: z.string().datetime('Payout paid date must be a valid ISO datetime string').optional(),
|
|
25
|
+
stripePayoutId: z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Policies schemas
|
|
29
|
+
export const cancellationSchema = z.object({
|
|
30
|
+
allowed: z.boolean({ required_error: 'Cancellation allowed must be true or false' }).default(true),
|
|
31
|
+
refundPercentage: z.number({ required_error: 'Refund percentage must be a number' }).min(0, 'Refund percentage cannot be less than 0').max(100, 'Refund percentage cannot exceed 100').default(100),
|
|
32
|
+
deadlineHours: z.number().min(0, 'Deadline hours cannot be negative').optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const policiesSchema = z.object({
|
|
36
|
+
cancellation: cancellationSchema.optional(),
|
|
37
|
+
transferable: z.boolean({ required_error: 'Transferable must be true or false' }).default(false),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Moderation schemas
|
|
41
|
+
export const flagSchema = z.object({
|
|
42
|
+
reportedBy: z.string({ required_error: 'Reported by user ID is required' }), // ObjectId as string
|
|
43
|
+
reason: z.string({ required_error: 'Report reason is required' }),
|
|
44
|
+
description: z.string({ required_error: 'Report description is required' }),
|
|
45
|
+
createdAt: z.string().datetime('Report created date must be a valid ISO datetime string').optional(),
|
|
46
|
+
status: z.enum(['pending', 'resolved', 'dismissed'], { required_error: 'Report status must be pending, resolved, or dismissed' }).default('pending'),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const moderationSchema = z.object({
|
|
50
|
+
isFlagged: z.boolean({ required_error: 'Is flagged must be true or false' }).default(false),
|
|
51
|
+
flags: z.array(flagSchema, { required_error: 'Flags must be an array' }).optional(),
|
|
52
|
+
suspendedUntil: z.string().datetime('Suspension date must be a valid ISO datetime string').optional(),
|
|
53
|
+
banReason: z.string().optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// SEO schema
|
|
57
|
+
export const seoSchema = z.object({
|
|
58
|
+
metaTitle: z.string().optional(),
|
|
59
|
+
metaDescription: z.string().optional(),
|
|
60
|
+
keywords: z.array(z.string(), { required_error: 'SEO keywords must be an array of strings' }).optional(),
|
|
61
|
+
ogImage: z.string().optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Features schema
|
|
65
|
+
export const featuresSchema = z.object({
|
|
66
|
+
isFeatured: z.boolean({ required_error: 'Is featured must be true or false' }).default(false),
|
|
67
|
+
isPremium: z.boolean({ required_error: 'Is premium must be true or false' }).default(false),
|
|
68
|
+
badges: z.array(z.string(), { required_error: 'Badges must be an array of strings' }).optional(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// History schema
|
|
72
|
+
export const historySchema = z.object({
|
|
73
|
+
action: z.string({ required_error: 'History action is required' }),
|
|
74
|
+
performedBy: z.string({ required_error: 'Performed by user ID is required' }), // ObjectId as string
|
|
75
|
+
timestamp: z.string().datetime('History timestamp must be a valid ISO datetime string').optional(),
|
|
76
|
+
changes: z.record(z.any()).optional(),
|
|
77
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const documentSchema = z.object({
|
|
4
|
+
type: z.enum(['venue_booking', 'permit', 'insurance', 'license', 'portfolio', 'other'], { required_error: 'Document type is required' }).optional(),
|
|
5
|
+
url: z.string({ required_error: 'Document URL is required' }).url('Document URL must be valid').optional(),
|
|
6
|
+
filename: z.string({ required_error: 'Document filename is required' }),
|
|
7
|
+
objectKey: z.string({ required_error: 'Document object key is required' }),
|
|
8
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const coverImageSchema = z.object({
|
|
4
|
+
alt: z.string({
|
|
5
|
+
required_error: 'Alt text is required',
|
|
6
|
+
invalid_type_error: 'Alt text must be a string'
|
|
7
|
+
}),
|
|
8
|
+
thumbnailUrl: z.string({
|
|
9
|
+
required_error: 'Thumbnail URL is required',
|
|
10
|
+
invalid_type_error: 'Thumbnail URL must be a string'
|
|
11
|
+
}),
|
|
12
|
+
url: z.string({
|
|
13
|
+
required_error: 'URL is required',
|
|
14
|
+
invalid_type_error: 'URL must be a string'
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const gallerySchema = z.array(z.object({
|
|
19
|
+
alt: z.string({
|
|
20
|
+
required_error: 'Alt text is required',
|
|
21
|
+
invalid_type_error: 'Alt text must be a string'
|
|
22
|
+
}),
|
|
23
|
+
thumbnailUrl: z.string({
|
|
24
|
+
required_error: 'Thumbnail URL is required',
|
|
25
|
+
invalid_type_error: 'Thumbnail URL must be a string'
|
|
26
|
+
}),
|
|
27
|
+
url: z.string({
|
|
28
|
+
required_error: 'URL is required',
|
|
29
|
+
invalid_type_error: 'URL must be a string'
|
|
30
|
+
})
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
export const mediaSchema = z.object({
|
|
34
|
+
coverImage: coverImageSchema,
|
|
35
|
+
gallery: gallerySchema.optional()
|
|
36
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const contactPersonSchema = z.object({
|
|
4
|
+
name: z.string({ required_error: 'Contact person name is required' }),
|
|
5
|
+
phone: z.string({ required_error: 'Contact person phone is required' }).min(11, 'Phone number must be 11 digits 11 digits'),
|
|
6
|
+
email: z.string({ required_error: 'Contact person email is required' }).email('Contact person email must be valid'),
|
|
7
|
+
designation: z.string().optional(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const organizerSchema = z.object({
|
|
11
|
+
role: z.enum(['event_organizer', 'venue_owner', 'authorized_rep', 'artist'], { required_error: 'Organizer role must be event_organizer, venue_owner, authorized_rep, or artist' }).optional(),
|
|
12
|
+
companyName: z.string().optional(),
|
|
13
|
+
contactPerson: contactPersonSchema,
|
|
14
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const scheduleSchema = z.object({
|
|
4
|
+
startDate: z.string({ required_error: 'Event start date is required' }).datetime('Start date must be a valid ISO datetime string'),
|
|
5
|
+
endDate: z.string({ required_error: 'Event end date is required' }).datetime('End date must be a valid ISO datetime string'),
|
|
6
|
+
timezone: z.string().optional(),
|
|
7
|
+
isMultiDay: z.boolean().optional(),
|
|
8
|
+
doors: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const priceSchema = z.object({
|
|
4
|
+
amount: z.number({ required_error: 'Ticket price amount is required' }).min(0, 'Ticket price cannot be negative'),
|
|
5
|
+
currency: z.string({ required_error: 'Ticket currency is required' }).default('BDT'),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const salesWindowSchema = z.object({
|
|
9
|
+
startDate: z.string().datetime('Sales start date must be a valid ISO datetime string').optional(),
|
|
10
|
+
endDate: z.string().datetime('Sales end date must be a valid ISO datetime string').optional(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const limitsSchema = z.object({
|
|
14
|
+
minPerOrder: z.number({ required_error: 'Min per order must be a number' }).int('Min per order must be an integer').min(1, 'Min per order must be at least 1').default(1),
|
|
15
|
+
maxPerOrder: z.number({ required_error: 'Max per order must be a number' }).int('Max per order must be an integer').min(1, 'Max per order must be at least 1').default(10),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const displayTicketSchema = z.object({
|
|
19
|
+
_id: z.string().optional(),
|
|
20
|
+
name: z.string({ required_error: 'Ticket name is required' }),
|
|
21
|
+
description: z.string().optional(),
|
|
22
|
+
price: priceSchema,
|
|
23
|
+
quantity: z.number({ required_error: 'Ticket quantity is required' }).int('Quantity must be an integer').positive('Quantity must be positive'),
|
|
24
|
+
salesWindow: salesWindowSchema.optional(),
|
|
25
|
+
limits: limitsSchema.optional(),
|
|
26
|
+
remaining: z.number().optional(),
|
|
27
|
+
sold: z.number().optional(),
|
|
28
|
+
reserved: z.number().optional(),
|
|
29
|
+
visibility: z.enum(['public', 'hidden', 'invite_only'], { required_error: 'Ticket visibility must be public, hidden, or invite_only' }).default('public').optional(),
|
|
30
|
+
status: z.enum(['active', 'inactive'], { required_error: 'Ticket status must be active or inactive' }).default('active').optional(),
|
|
31
|
+
benefits: z.array(z.string(), { required_error: 'Benefits must be an array of strings' }).optional(),
|
|
32
|
+
tier: z.enum(['early_bird', 'regular', 'vip'], { required_error: 'Ticket tier must be early_bird, regular or vip' }).default('regular')
|
|
33
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const venueTypeSchema = z.enum(['indoor', 'outdoor', 'hybrid'], { required_error: 'Venue type must be indoor, outdoor, or hybrid' }).optional();
|
|
4
|
+
|
|
5
|
+
export const addressSchema = z.object({
|
|
6
|
+
street: z.string({ required_error: 'Street is required' }).min(1, 'Street is required'),
|
|
7
|
+
city: z.string({ required_error: 'City is required' }).min(1, 'City is required'),
|
|
8
|
+
country: z.string({ required_error: 'Country is required' }).min(1, 'Country is required'),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const venueSchema = z.object({
|
|
12
|
+
name: z.string({ required_error: 'Venue name is required' }).min(1, 'Venue name is required'),
|
|
13
|
+
address: addressSchema,
|
|
14
|
+
coordinates: z.object({
|
|
15
|
+
type: z.literal('Point', { required_error: 'Coordinates type must be Point' }),
|
|
16
|
+
coordinates: z.tuple([z.number({ required_error: 'Longitude is required' }), z.number({ required_error: 'Latitude is required' })], { required_error: 'Coordinates array [lng, lat] is required' }), // [lng, lat]
|
|
17
|
+
}).optional(),
|
|
18
|
+
capacity: z.number({ required_error: 'Venue capacity is required' }).int('Capacity must be an integer').positive('Capacity must be positive').min(10, 'Capacity must be at least 10'),
|
|
19
|
+
type: venueTypeSchema,
|
|
20
|
+
parking: z.boolean().optional(),
|
|
21
|
+
publicTransit: z.string().optional(),
|
|
22
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { backblazeUploadUrlSchema } from './utils/backblaze.schema';
|
|
3
|
+
import { imageKitAuthSchema, imageKitFinalizeSchema, imageKitTrackSchema } from './utils/imagekit.schema';
|
|
4
|
+
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// MEDIA SCHEMAS
|
|
7
|
+
// =============================================================================
|
|
8
|
+
|
|
9
|
+
// Re-export utility schemas for convenience
|
|
10
|
+
export { backblazeUploadUrlSchema } from './utils/backblaze.schema';
|
|
11
|
+
export { imageKitAuthSchema, imageKitFinalizeSchema, imageKitTrackSchema } from './utils/imagekit.schema';
|
|
12
|
+
|
|
13
|
+
// Common media types enum
|
|
14
|
+
export const mediaTypeSchema = z.enum(['event_cover', 'event_gallery', 'verification_doc']);
|
|
15
|
+
|
|
16
|
+
// File upload response schema
|
|
17
|
+
export const fileUploadResponseSchema = z.object({
|
|
18
|
+
url: z.string(),
|
|
19
|
+
key: z.string(),
|
|
20
|
+
bucket: z.string(),
|
|
21
|
+
fileName: z.string(),
|
|
22
|
+
fileType: z.string(),
|
|
23
|
+
size: z.number(),
|
|
24
|
+
uploadedAt: z.date(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Document schema (used in events)
|
|
28
|
+
export const documentSchema = z.object({
|
|
29
|
+
id: z.string().optional(),
|
|
30
|
+
name: z.string({ required_error: 'Document name is required' }),
|
|
31
|
+
url: z.string({ required_error: 'Document URL is required' }),
|
|
32
|
+
type: mediaTypeSchema,
|
|
33
|
+
size: z.number({ required_error: 'Document size is required' }),
|
|
34
|
+
mimeType: z.string({ required_error: 'Document MIME type is required' }),
|
|
35
|
+
uploadedAt: z.date().optional(),
|
|
36
|
+
objectKey: z.string().optional(), // For S3/Backblaze reference
|
|
37
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { mediaTypeSchema, fileUploadResponseSchema } from './media.schema';
|
|
3
|
+
|
|
4
|
+
// =============================================================================
|
|
5
|
+
// TYPE EXPORTS
|
|
6
|
+
// =============================================================================
|
|
7
|
+
|
|
8
|
+
// Media types
|
|
9
|
+
export type MediaType = z.infer<typeof mediaTypeSchema>;
|
|
10
|
+
export type FileUploadResponse = z.infer<typeof fileUploadResponseSchema>;
|
|
11
|
+
|
|
12
|
+
// Backblaze types
|
|
13
|
+
export type BackblazeUploadUrlInput = z.infer<typeof import('./utils/backblaze.schema').backblazeUploadUrlSchema>;
|
|
14
|
+
|
|
15
|
+
// ImageKit types
|
|
16
|
+
export type ImageKitAuthInput = z.infer<typeof import('./utils/imagekit.schema').imageKitAuthSchema>;
|
|
17
|
+
export type ImageKitFinalizeInput = z.infer<typeof import('./utils/imagekit.schema').imageKitFinalizeSchema>;
|
|
18
|
+
export type ImageKitTrackInput = z.infer<typeof import('./utils/imagekit.schema').imageKitTrackSchema>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Schema for Backblaze upload URL endpoint
|
|
4
|
+
export const backblazeUploadUrlSchema = z.object({
|
|
5
|
+
filename: z.string({ required_error: 'File name is required' }),
|
|
6
|
+
fileType: z.string({ required_error: 'File type is required' }),
|
|
7
|
+
documentType: z.enum(['event_cover', 'event_gallery', 'verification_doc']).default('verification_doc'),
|
|
8
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Schema for ImageKit auth endpoint - GET request, no body needed
|
|
4
|
+
export const imageKitAuthSchema = z.object({});
|
|
5
|
+
|
|
6
|
+
// Schema for ImageKit finalize endpoint
|
|
7
|
+
export const imageKitFinalizeSchema = z.object({
|
|
8
|
+
fileId: z.string({ required_error: 'File ID is required' }),
|
|
9
|
+
fromFolder: z.string({ required_error: 'From folder is required' }),
|
|
10
|
+
toFolder: z.string({ required_error: 'To folder is required' }),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Schema for ImageKit track endpoint
|
|
14
|
+
export const imageKitTrackSchema = z.object({
|
|
15
|
+
fileId: z.string({ required_error: 'File ID is required' }),
|
|
16
|
+
url: z.string({ required_error: 'URL is required' }),
|
|
17
|
+
filename: z.string({ required_error: 'Filename is required' }),
|
|
18
|
+
type: z.enum(['event_cover', 'event_gallery', 'verification_doc']),
|
|
19
|
+
status: z.enum(['temp', 'permanent', 'deleted']).default('temp'),
|
|
20
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Order ticket schema (embedded in order)
|
|
4
|
+
export const orderTicketSchema = z.object({
|
|
5
|
+
ticketVariantId: z.string(),
|
|
6
|
+
variantName: z.string(),
|
|
7
|
+
quantity: z.number().min(1),
|
|
8
|
+
pricePerTicket: z.number().min(0),
|
|
9
|
+
subtotal: z.number().min(0)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// Pricing schema (embedded in order)
|
|
13
|
+
export const orderPricingSchema = z.object({
|
|
14
|
+
subtotal: z.number().min(0),
|
|
15
|
+
platformFee: z.number().min(0),
|
|
16
|
+
paymentFee: z.number().min(0),
|
|
17
|
+
total: z.number().min(0),
|
|
18
|
+
currency: z.string().default('BDT'),
|
|
19
|
+
hostPayout: z.number().min(0)
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Refund schema (embedded in order)
|
|
23
|
+
export const refundSchema = z.object({
|
|
24
|
+
reason: z.enum(['event_cancelled', 'user_request', 'fraud']),
|
|
25
|
+
amount: z.number().min(0),
|
|
26
|
+
refundedAt: z.date().default(() => new Date()),
|
|
27
|
+
stripeRefundId: z.string().optional()
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Main order schema
|
|
31
|
+
export const orderSchema = z.object({
|
|
32
|
+
_id: z.string().optional(), // MongoDB ObjectId
|
|
33
|
+
orderNumber: z.string().regex(/^ORD-\d{6}-[A-Z0-9]{6}$/), // ORD-123456-ABC123
|
|
34
|
+
|
|
35
|
+
// WHO
|
|
36
|
+
userId: z.string(), // Buyer
|
|
37
|
+
|
|
38
|
+
// WHAT
|
|
39
|
+
eventId: z.string(), // Which event
|
|
40
|
+
|
|
41
|
+
tickets: z.array(orderTicketSchema).min(1),
|
|
42
|
+
|
|
43
|
+
// MONEY
|
|
44
|
+
pricing: orderPricingSchema,
|
|
45
|
+
|
|
46
|
+
// STATUS
|
|
47
|
+
status: z.enum(['pending', 'confirmed', 'cancelled', 'refunded']).default('pending'),
|
|
48
|
+
|
|
49
|
+
// PAYMENT
|
|
50
|
+
paymentMethod: z.enum(['card', 'bkash', 'bank_transfer']),
|
|
51
|
+
paymentStatus: z.enum(['pending', 'succeeded', 'failed']).default('pending'),
|
|
52
|
+
paidAt: z.date().optional(),
|
|
53
|
+
|
|
54
|
+
// TICKETS ISSUED
|
|
55
|
+
ticketIds: z.array(z.string()).default([]),
|
|
56
|
+
|
|
57
|
+
// LIFECYCLE
|
|
58
|
+
createdAt: z.date().default(() => new Date()),
|
|
59
|
+
expiresAt: z.date(), // Must be set when creating
|
|
60
|
+
confirmedAt: z.date().optional(),
|
|
61
|
+
cancelledAt: z.date().optional(),
|
|
62
|
+
refundedAt: z.date().optional(),
|
|
63
|
+
|
|
64
|
+
// CONTACT
|
|
65
|
+
buyerEmail: z.string().email(),
|
|
66
|
+
buyerPhone: z.string().optional(),
|
|
67
|
+
|
|
68
|
+
// AUDIT
|
|
69
|
+
ipAddress: z.string().optional(),
|
|
70
|
+
userAgent: z.string().optional(),
|
|
71
|
+
|
|
72
|
+
// REFUND (if applicable)
|
|
73
|
+
refund: refundSchema.optional()
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// API Request/Response schemas
|
|
77
|
+
export const createOrderSchema = z.object({
|
|
78
|
+
eventId: z.string(),
|
|
79
|
+
tickets: z.array(z.object({
|
|
80
|
+
ticketVariantId: z.string(),
|
|
81
|
+
variantName: z.string(),
|
|
82
|
+
quantity: z.number().min(1),
|
|
83
|
+
pricePerTicket: z.number().min(0)
|
|
84
|
+
})).min(1),
|
|
85
|
+
paymentMethod: z.enum(['card', 'bkash', 'bank_transfer']),
|
|
86
|
+
buyerEmail: z.string().email(),
|
|
87
|
+
buyerPhone: z.string().optional()
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const confirmOrderSchema = z.object({
|
|
91
|
+
ticketIds: z.array(z.string())
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const refundOrderSchema = z.object({
|
|
95
|
+
reason: z.enum(['event_cancelled', 'user_request', 'fraud']),
|
|
96
|
+
amount: z.number().min(0)
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const updateOrderStatusSchema = z.object({
|
|
100
|
+
status: z.enum(['pending', 'confirmed', 'cancelled', 'refunded']),
|
|
101
|
+
adminNotes: z.string().optional()
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Response schemas
|
|
105
|
+
export const orderResponseSchema = orderSchema;
|
|
106
|
+
export const ordersListResponseSchema = z.array(orderResponseSchema);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import {
|
|
3
|
+
orderSchema,
|
|
4
|
+
orderTicketSchema,
|
|
5
|
+
orderPricingSchema,
|
|
6
|
+
refundSchema,
|
|
7
|
+
createOrderSchema,
|
|
8
|
+
confirmOrderSchema,
|
|
9
|
+
refundOrderSchema,
|
|
10
|
+
updateOrderStatusSchema,
|
|
11
|
+
orderResponseSchema,
|
|
12
|
+
ordersListResponseSchema
|
|
13
|
+
} from './orders.schema';
|
|
14
|
+
import { PaymentMethod } from './payments.type';
|
|
15
|
+
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// TYPE EXPORTS
|
|
18
|
+
// =============================================================================
|
|
19
|
+
|
|
20
|
+
// Embedded schema types
|
|
21
|
+
export type OrderTicket = z.infer<typeof orderTicketSchema>;
|
|
22
|
+
export type OrderPricing = z.infer<typeof orderPricingSchema>;
|
|
23
|
+
export type Refund = z.infer<typeof refundSchema>;
|
|
24
|
+
|
|
25
|
+
// Main order types
|
|
26
|
+
export type Order = z.infer<typeof orderSchema>;
|
|
27
|
+
export type OrderStatus = Order['status'];
|
|
28
|
+
|
|
29
|
+
// API request/response types
|
|
30
|
+
export type CreateOrderRequest = z.infer<typeof createOrderSchema>;
|
|
31
|
+
export type ConfirmOrderRequest = z.infer<typeof confirmOrderSchema>;
|
|
32
|
+
export type RefundOrderRequest = z.infer<typeof refundOrderSchema>;
|
|
33
|
+
export type UpdateOrderStatusRequest = z.infer<typeof updateOrderStatusSchema>;
|
|
34
|
+
|
|
35
|
+
export type OrderResponse = z.infer<typeof orderResponseSchema>;
|
|
36
|
+
export type OrdersListResponse = z.infer<typeof ordersListResponseSchema>;
|
|
37
|
+
|
|
38
|
+
// Service method parameter types
|
|
39
|
+
export interface CreateOrderData {
|
|
40
|
+
userId: string;
|
|
41
|
+
eventId: string;
|
|
42
|
+
tickets: Array<{
|
|
43
|
+
ticketVariantId: string;
|
|
44
|
+
variantName: string;
|
|
45
|
+
quantity: number;
|
|
46
|
+
pricePerTicket: number;
|
|
47
|
+
}>;
|
|
48
|
+
paymentMethod: PaymentMethod;
|
|
49
|
+
buyerEmail: string;
|
|
50
|
+
buyerPhone?: string;
|
|
51
|
+
ipAddress?: string;
|
|
52
|
+
userAgent?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Service response types
|
|
56
|
+
export interface CreateOrderResponse {
|
|
57
|
+
orderId: string;
|
|
58
|
+
orderNumber: string;
|
|
59
|
+
paymentIntentId: string;
|
|
60
|
+
total: number;
|
|
61
|
+
expiresAt: Date;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Utility types for frontend (populated responses)
|
|
65
|
+
export interface OrderWithEvent extends Omit<Order, 'eventId'> {
|
|
66
|
+
eventId: {
|
|
67
|
+
_id: string;
|
|
68
|
+
title: string;
|
|
69
|
+
schedule: {
|
|
70
|
+
venue: {
|
|
71
|
+
name: string;
|
|
72
|
+
};
|
|
73
|
+
startDate: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface OrderWithTickets extends Omit<Order, 'ticketIds'> {
|
|
79
|
+
ticketIds: Array<{
|
|
80
|
+
_id: string;
|
|
81
|
+
ticketNumber: string;
|
|
82
|
+
qrCode: string;
|
|
83
|
+
status: 'active' | 'used' | 'cancelled';
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Payment status enum
|
|
4
|
+
export const paymentStatusSchema = z.enum(['pending', 'succeeded', 'failed', 'refunded']);
|
|
5
|
+
|
|
6
|
+
// Payment method enum
|
|
7
|
+
export const paymentMethodSchema = z.enum(['bkash', 'card']);
|
|
8
|
+
|
|
9
|
+
// Card brand enum
|
|
10
|
+
export const cardBrandSchema = z.enum(['visa', 'mastercard', 'amex', 'discover']);
|
|
11
|
+
|
|
12
|
+
// Failure codes enum
|
|
13
|
+
export const failureCodeSchema = z.enum([
|
|
14
|
+
'insufficient_funds',
|
|
15
|
+
'card_declined',
|
|
16
|
+
'expired_card',
|
|
17
|
+
'incorrect_cvc',
|
|
18
|
+
'processing_error',
|
|
19
|
+
'issuer_not_available',
|
|
20
|
+
'invalid_card_number'
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
// Main payment schema
|
|
24
|
+
export const paymentSchema = z.object({
|
|
25
|
+
_id: z.string().optional(), // MongoDB ObjectId
|
|
26
|
+
|
|
27
|
+
// LINKS
|
|
28
|
+
orderId: z.string(), // Which order
|
|
29
|
+
userId: z.string(), // Who paid
|
|
30
|
+
|
|
31
|
+
// STRIPE
|
|
32
|
+
paymentId: z.string(), // Stripe PI
|
|
33
|
+
|
|
34
|
+
// MONEY
|
|
35
|
+
amount: z.number().min(0),
|
|
36
|
+
currency: z.string().default('BDT'),
|
|
37
|
+
|
|
38
|
+
// STATUS
|
|
39
|
+
status: paymentStatusSchema,
|
|
40
|
+
|
|
41
|
+
// METADATA
|
|
42
|
+
paymentMethod: paymentMethodSchema,
|
|
43
|
+
last4: z.string().optional(), // Card last 4 digits
|
|
44
|
+
brand: cardBrandSchema.optional(), // Card brand
|
|
45
|
+
|
|
46
|
+
// FAILURE (if failed)
|
|
47
|
+
failureCode: failureCodeSchema.optional(),
|
|
48
|
+
failureMessage: z.string().optional(),
|
|
49
|
+
|
|
50
|
+
// REFUND (if refunded)
|
|
51
|
+
refundId: z.string().optional(), // Stripe refund ID
|
|
52
|
+
refundAmount: z.number().min(0).optional(),
|
|
53
|
+
refundedAt: z.date().optional(),
|
|
54
|
+
|
|
55
|
+
// TIMESTAMPS
|
|
56
|
+
createdAt: z.date().default(() => new Date()),
|
|
57
|
+
succeededAt: z.date().optional(),
|
|
58
|
+
failedAt: z.date().optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// API request/response schemas
|
|
62
|
+
export const createPaymentSchema = z.object({
|
|
63
|
+
orderId: z.string(),
|
|
64
|
+
amount: z.number().min(0),
|
|
65
|
+
paymentMethod: paymentMethodSchema,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const updatePaymentStatusSchema = z.object({
|
|
69
|
+
status: paymentStatusSchema,
|
|
70
|
+
failureCode: failureCodeSchema.optional(),
|
|
71
|
+
failureMessage: z.string().optional(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const refundPaymentSchema = z.object({
|
|
75
|
+
refundAmount: z.number().min(0),
|
|
76
|
+
reason: z.string(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Response schemas
|
|
80
|
+
export const paymentResponseSchema = paymentSchema;
|
|
81
|
+
export const paymentsListResponseSchema = z.array(paymentResponseSchema);
|