@devlider001/washlab-backend 1.0.4 → 1.0.6
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/convex/_generated/api.d.ts +2 -0
- package/convex/admin.d.ts +1 -1
- package/convex/audit.d.ts +39 -0
- package/convex/customers.d.ts +12 -5
- package/convex/lib/auth.d.ts +24 -1
- package/convex/notifications.d.ts +170 -0
- package/convex/schema.d.ts +53 -2
- package/dist/convex/admin.d.ts +377 -0
- package/dist/convex/admin.d.ts.map +1 -0
- package/dist/convex/admin.js +959 -0
- package/dist/convex/admin.js.map +1 -0
- package/dist/convex/analytics.d.ts +87 -0
- package/dist/convex/analytics.d.ts.map +1 -0
- package/dist/convex/analytics.js +361 -0
- package/dist/convex/analytics.js.map +1 -0
- package/dist/convex/attendants.d.ts +140 -0
- package/dist/convex/attendants.d.ts.map +1 -0
- package/dist/convex/attendants.js +337 -0
- package/dist/convex/attendants.js.map +1 -0
- package/dist/convex/audit.d.ts +158 -0
- package/dist/convex/audit.d.ts.map +1 -0
- package/dist/convex/audit.js +184 -0
- package/dist/convex/audit.js.map +1 -0
- package/dist/convex/clerk.d.ts +53 -0
- package/dist/convex/clerk.d.ts.map +1 -0
- package/dist/convex/clerk.js +316 -0
- package/dist/convex/clerk.js.map +1 -0
- package/dist/convex/customers.d.ts +224 -0
- package/dist/convex/customers.d.ts.map +1 -0
- package/dist/convex/customers.js +504 -0
- package/dist/convex/customers.js.map +1 -0
- package/dist/convex/http.d.ts +3 -0
- package/dist/convex/http.d.ts.map +1 -0
- package/dist/convex/http.js +115 -0
- package/dist/convex/http.js.map +1 -0
- package/dist/convex/lib/audit.d.ts +36 -0
- package/dist/convex/lib/audit.d.ts.map +1 -0
- package/dist/convex/lib/audit.js +59 -0
- package/dist/convex/lib/audit.js.map +1 -0
- package/dist/convex/lib/auth.d.ts +96 -0
- package/dist/convex/lib/auth.d.ts.map +1 -0
- package/dist/convex/lib/auth.js +94 -0
- package/dist/convex/lib/auth.js.map +1 -0
- package/dist/convex/lib/utils.d.ts +38 -0
- package/dist/convex/lib/utils.d.ts.map +1 -0
- package/dist/convex/lib/utils.js +71 -0
- package/dist/convex/lib/utils.js.map +1 -0
- package/dist/convex/loyalty.d.ts +82 -0
- package/dist/convex/loyalty.d.ts.map +1 -0
- package/dist/convex/loyalty.js +286 -0
- package/dist/convex/loyalty.js.map +1 -0
- package/dist/convex/orders.d.ts +326 -0
- package/dist/convex/orders.d.ts.map +1 -0
- package/dist/convex/orders.js +570 -0
- package/dist/convex/orders.js.map +1 -0
- package/dist/convex/payments.d.ts +134 -0
- package/dist/convex/payments.d.ts.map +1 -0
- package/dist/convex/payments.js +360 -0
- package/dist/convex/payments.js.map +1 -0
- package/dist/convex/resources.d.ts +119 -0
- package/dist/convex/resources.d.ts.map +1 -0
- package/dist/convex/resources.js +283 -0
- package/dist/convex/resources.js.map +1 -0
- package/dist/convex/schema.d.ts +450 -0
- package/dist/convex/schema.d.ts.map +1 -0
- package/dist/convex/schema.js +347 -0
- package/dist/convex/schema.js.map +1 -0
- package/dist/convex/vouchers.d.ts +187 -0
- package/dist/convex/vouchers.d.ts.map +1 -0
- package/dist/convex/vouchers.js +464 -0
- package/dist/convex/vouchers.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +5 -3
- package/convex/_generated/api.js +0 -23
- package/convex/_generated/server.js +0 -93
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { query, mutation } from "./_generated/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { getCurrentAdmin, getCurrentCustomer, getCurrentAttendant } from "./lib/auth";
|
|
4
|
+
import { createAuditLog } from "./lib/audit";
|
|
5
|
+
import { getCurrentTimestamp } from "./lib/utils";
|
|
6
|
+
/**
|
|
7
|
+
* Voucher Functions
|
|
8
|
+
*
|
|
9
|
+
* Handles discount vouchers and promo codes creation, validation, and application.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Get all vouchers (admin only)
|
|
13
|
+
*/
|
|
14
|
+
export const getAll = query({
|
|
15
|
+
args: {
|
|
16
|
+
includeInactive: v.optional(v.boolean()),
|
|
17
|
+
cursor: v.optional(v.string()),
|
|
18
|
+
numItems: v.optional(v.number()),
|
|
19
|
+
},
|
|
20
|
+
handler: async (ctx, args) => {
|
|
21
|
+
await getCurrentAdmin(ctx);
|
|
22
|
+
const numItems = args.numItems ?? 20;
|
|
23
|
+
const result = await ctx.db
|
|
24
|
+
.query("vouchers")
|
|
25
|
+
.filter((q) => q.eq(q.field("isDeleted"), false))
|
|
26
|
+
.paginate({
|
|
27
|
+
cursor: args.cursor ?? null,
|
|
28
|
+
numItems,
|
|
29
|
+
});
|
|
30
|
+
let filtered = result.page;
|
|
31
|
+
if (!args.includeInactive) {
|
|
32
|
+
filtered = filtered.filter((v) => v.isActive);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
page: filtered,
|
|
36
|
+
isDone: result.isDone,
|
|
37
|
+
continueCursor: result.continueCursor,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Get active vouchers (public - for customers/attendants)
|
|
43
|
+
*/
|
|
44
|
+
export const getActive = query({
|
|
45
|
+
args: {
|
|
46
|
+
branchId: v.optional(v.id("branches")),
|
|
47
|
+
},
|
|
48
|
+
handler: async (ctx, args) => {
|
|
49
|
+
const now = getCurrentTimestamp();
|
|
50
|
+
const vouchers = await ctx.db
|
|
51
|
+
.query("vouchers")
|
|
52
|
+
.withIndex("by_active", (q) => q.eq("isActive", true))
|
|
53
|
+
.filter((q) => q.and(q.eq(q.field("isDeleted"), false), q.or(q.eq(q.field("validFrom"), undefined), q.lte(q.field("validFrom"), now)), q.or(q.eq(q.field("validUntil"), undefined), q.gte(q.field("validUntil"), now))))
|
|
54
|
+
.collect();
|
|
55
|
+
let filtered = vouchers;
|
|
56
|
+
// Filter by branch if specified
|
|
57
|
+
if (args.branchId) {
|
|
58
|
+
filtered = filtered.filter((v) => {
|
|
59
|
+
if (!v.applicableBranches || v.applicableBranches.length === 0) {
|
|
60
|
+
return true; // Applies to all branches
|
|
61
|
+
}
|
|
62
|
+
return v.applicableBranches.includes(args.branchId);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return filtered;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Get voucher by code
|
|
70
|
+
*/
|
|
71
|
+
export const getByCode = query({
|
|
72
|
+
args: {
|
|
73
|
+
code: v.string(),
|
|
74
|
+
},
|
|
75
|
+
handler: async (ctx, args) => {
|
|
76
|
+
const voucher = await ctx.db
|
|
77
|
+
.query("vouchers")
|
|
78
|
+
.withIndex("by_code", (q) => q.eq("code", args.code.toUpperCase()))
|
|
79
|
+
.first();
|
|
80
|
+
if (!voucher || voucher.isDeleted || !voucher.isActive) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const now = getCurrentTimestamp();
|
|
84
|
+
// Check validity dates
|
|
85
|
+
if (voucher.validFrom && voucher.validFrom > now) {
|
|
86
|
+
return null; // Not yet valid
|
|
87
|
+
}
|
|
88
|
+
if (voucher.validUntil && voucher.validUntil < now) {
|
|
89
|
+
return null; // Expired
|
|
90
|
+
}
|
|
91
|
+
return voucher;
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Validate voucher for order
|
|
96
|
+
*/
|
|
97
|
+
export const validate = query({
|
|
98
|
+
args: {
|
|
99
|
+
code: v.string(),
|
|
100
|
+
orderTotal: v.number(),
|
|
101
|
+
branchId: v.id("branches"),
|
|
102
|
+
serviceType: v.optional(v.union(v.literal("wash_only"), v.literal("wash_and_dry"), v.literal("dry_only"))),
|
|
103
|
+
},
|
|
104
|
+
handler: async (ctx, args) => {
|
|
105
|
+
const voucher = await ctx.db
|
|
106
|
+
.query("vouchers")
|
|
107
|
+
.withIndex("by_code", (q) => q.eq("code", args.code.toUpperCase()))
|
|
108
|
+
.first();
|
|
109
|
+
if (!voucher || voucher.isDeleted || !voucher.isActive) {
|
|
110
|
+
return {
|
|
111
|
+
valid: false,
|
|
112
|
+
error: "Voucher not found or inactive",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const now = getCurrentTimestamp();
|
|
116
|
+
// Check validity dates
|
|
117
|
+
if (voucher.validFrom && voucher.validFrom > now) {
|
|
118
|
+
return {
|
|
119
|
+
valid: false,
|
|
120
|
+
error: "Voucher is not yet valid",
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (voucher.validUntil && voucher.validUntil < now) {
|
|
124
|
+
return {
|
|
125
|
+
valid: false,
|
|
126
|
+
error: "Voucher has expired",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Check usage limit
|
|
130
|
+
if (voucher.usedCount >= voucher.usageLimit) {
|
|
131
|
+
return {
|
|
132
|
+
valid: false,
|
|
133
|
+
error: "Voucher usage limit reached",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Check minimum order value
|
|
137
|
+
if (voucher.minOrderValue && args.orderTotal < voucher.minOrderValue) {
|
|
138
|
+
return {
|
|
139
|
+
valid: false,
|
|
140
|
+
error: `Minimum order value of ₵${voucher.minOrderValue} required`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Check branch restriction
|
|
144
|
+
if (voucher.applicableBranches && voucher.applicableBranches.length > 0) {
|
|
145
|
+
if (!voucher.applicableBranches.includes(args.branchId)) {
|
|
146
|
+
return {
|
|
147
|
+
valid: false,
|
|
148
|
+
error: "Voucher not valid for this branch",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Check service type restriction
|
|
153
|
+
if (args.serviceType && voucher.applicableServiceTypes && voucher.applicableServiceTypes.length > 0) {
|
|
154
|
+
if (!voucher.applicableServiceTypes.includes(args.serviceType)) {
|
|
155
|
+
return {
|
|
156
|
+
valid: false,
|
|
157
|
+
error: "Voucher not valid for this service type",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Calculate discount amount
|
|
162
|
+
let discountAmount = 0;
|
|
163
|
+
if (voucher.discountType === "percentage") {
|
|
164
|
+
discountAmount = (args.orderTotal * voucher.discountValue) / 100;
|
|
165
|
+
}
|
|
166
|
+
else if (voucher.discountType === "fixed") {
|
|
167
|
+
discountAmount = voucher.discountValue;
|
|
168
|
+
}
|
|
169
|
+
else if (voucher.discountType === "free_wash") {
|
|
170
|
+
discountAmount = args.orderTotal; // 100% discount
|
|
171
|
+
}
|
|
172
|
+
// Don't allow discount to exceed order total
|
|
173
|
+
discountAmount = Math.min(discountAmount, args.orderTotal);
|
|
174
|
+
return {
|
|
175
|
+
valid: true,
|
|
176
|
+
voucher: {
|
|
177
|
+
_id: voucher._id,
|
|
178
|
+
code: voucher.code,
|
|
179
|
+
name: voucher.name,
|
|
180
|
+
discountType: voucher.discountType,
|
|
181
|
+
discountValue: voucher.discountValue,
|
|
182
|
+
},
|
|
183
|
+
discountAmount: Math.round(discountAmount * 100) / 100,
|
|
184
|
+
finalPrice: Math.round((args.orderTotal - discountAmount) * 100) / 100,
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* Create voucher (admin only)
|
|
190
|
+
*/
|
|
191
|
+
export const create = mutation({
|
|
192
|
+
args: {
|
|
193
|
+
code: v.string(),
|
|
194
|
+
name: v.optional(v.string()),
|
|
195
|
+
discountType: v.union(v.literal("percentage"), v.literal("fixed"), v.literal("free_wash")),
|
|
196
|
+
discountValue: v.number(),
|
|
197
|
+
usageLimit: v.number(),
|
|
198
|
+
maxUsesPerCustomer: v.optional(v.number()),
|
|
199
|
+
validFrom: v.optional(v.number()),
|
|
200
|
+
validUntil: v.optional(v.number()),
|
|
201
|
+
minOrderValue: v.optional(v.number()),
|
|
202
|
+
applicableBranches: v.optional(v.array(v.id("branches"))),
|
|
203
|
+
applicableServiceTypes: v.optional(v.array(v.union(v.literal("wash_only"), v.literal("wash_and_dry"), v.literal("dry_only")))),
|
|
204
|
+
description: v.optional(v.string()),
|
|
205
|
+
},
|
|
206
|
+
handler: async (ctx, args) => {
|
|
207
|
+
const admin = await getCurrentAdmin(ctx);
|
|
208
|
+
// Check if code already exists
|
|
209
|
+
const existing = await ctx.db
|
|
210
|
+
.query("vouchers")
|
|
211
|
+
.withIndex("by_code", (q) => q.eq("code", args.code.toUpperCase()))
|
|
212
|
+
.first();
|
|
213
|
+
if (existing && !existing.isDeleted) {
|
|
214
|
+
throw new Error("Voucher code already exists");
|
|
215
|
+
}
|
|
216
|
+
const now = getCurrentTimestamp();
|
|
217
|
+
const voucherId = await ctx.db.insert("vouchers", {
|
|
218
|
+
code: args.code.toUpperCase(),
|
|
219
|
+
name: args.name,
|
|
220
|
+
discountType: args.discountType,
|
|
221
|
+
discountValue: args.discountValue,
|
|
222
|
+
usageLimit: args.usageLimit,
|
|
223
|
+
usedCount: 0,
|
|
224
|
+
maxUsesPerCustomer: args.maxUsesPerCustomer,
|
|
225
|
+
isActive: true,
|
|
226
|
+
validFrom: args.validFrom,
|
|
227
|
+
validUntil: args.validUntil,
|
|
228
|
+
minOrderValue: args.minOrderValue,
|
|
229
|
+
applicableBranches: args.applicableBranches,
|
|
230
|
+
applicableServiceTypes: args.applicableServiceTypes,
|
|
231
|
+
createdAt: now,
|
|
232
|
+
createdBy: admin._id,
|
|
233
|
+
description: args.description,
|
|
234
|
+
isDeleted: false,
|
|
235
|
+
});
|
|
236
|
+
await createAuditLog({
|
|
237
|
+
ctx,
|
|
238
|
+
actorId: admin._id,
|
|
239
|
+
actorType: "admin",
|
|
240
|
+
actorRole: admin.role,
|
|
241
|
+
action: "voucher.created",
|
|
242
|
+
entityType: "voucher",
|
|
243
|
+
entityId: voucherId,
|
|
244
|
+
details: JSON.stringify({ code: args.code, discountType: args.discountType }),
|
|
245
|
+
});
|
|
246
|
+
return voucherId;
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
/**
|
|
250
|
+
* Update voucher (admin only)
|
|
251
|
+
*/
|
|
252
|
+
export const update = mutation({
|
|
253
|
+
args: {
|
|
254
|
+
voucherId: v.id("vouchers"),
|
|
255
|
+
name: v.optional(v.string()),
|
|
256
|
+
discountType: v.optional(v.union(v.literal("percentage"), v.literal("fixed"), v.literal("free_wash"))),
|
|
257
|
+
discountValue: v.optional(v.number()),
|
|
258
|
+
usageLimit: v.optional(v.number()),
|
|
259
|
+
maxUsesPerCustomer: v.optional(v.number()),
|
|
260
|
+
isActive: v.optional(v.boolean()),
|
|
261
|
+
validFrom: v.optional(v.number()),
|
|
262
|
+
validUntil: v.optional(v.number()),
|
|
263
|
+
minOrderValue: v.optional(v.number()),
|
|
264
|
+
applicableBranches: v.optional(v.array(v.id("branches"))),
|
|
265
|
+
applicableServiceTypes: v.optional(v.array(v.union(v.literal("wash_only"), v.literal("wash_and_dry"), v.literal("dry_only")))),
|
|
266
|
+
description: v.optional(v.string()),
|
|
267
|
+
},
|
|
268
|
+
handler: async (ctx, args) => {
|
|
269
|
+
const admin = await getCurrentAdmin(ctx);
|
|
270
|
+
const voucher = await ctx.db.get(args.voucherId);
|
|
271
|
+
if (!voucher || voucher.isDeleted) {
|
|
272
|
+
throw new Error("Voucher not found");
|
|
273
|
+
}
|
|
274
|
+
const { voucherId, ...updates } = args;
|
|
275
|
+
await ctx.db.patch(args.voucherId, updates);
|
|
276
|
+
await createAuditLog({
|
|
277
|
+
ctx,
|
|
278
|
+
actorId: admin._id,
|
|
279
|
+
actorType: "admin",
|
|
280
|
+
actorRole: admin.role,
|
|
281
|
+
action: "voucher.updated",
|
|
282
|
+
entityType: "voucher",
|
|
283
|
+
entityId: args.voucherId,
|
|
284
|
+
oldValue: JSON.stringify(voucher),
|
|
285
|
+
newValue: JSON.stringify({ ...voucher, ...updates }),
|
|
286
|
+
});
|
|
287
|
+
return args.voucherId;
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
/**
|
|
291
|
+
* Apply voucher to order
|
|
292
|
+
*/
|
|
293
|
+
export const applyToOrder = mutation({
|
|
294
|
+
args: {
|
|
295
|
+
voucherCode: v.string(),
|
|
296
|
+
orderId: v.id("orders"),
|
|
297
|
+
},
|
|
298
|
+
handler: async (ctx, args) => {
|
|
299
|
+
// Allow both customers and attendants to apply vouchers
|
|
300
|
+
let customer;
|
|
301
|
+
let attendant;
|
|
302
|
+
try {
|
|
303
|
+
customer = await getCurrentCustomer(ctx);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
try {
|
|
307
|
+
attendant = await getCurrentAttendant(ctx);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
throw new Error("Authentication required");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const order = await ctx.db.get(args.orderId);
|
|
314
|
+
if (!order || order.isDeleted) {
|
|
315
|
+
throw new Error("Order not found");
|
|
316
|
+
}
|
|
317
|
+
// Verify customer owns the order (if customer is applying)
|
|
318
|
+
if (customer && order.customerId !== customer._id) {
|
|
319
|
+
throw new Error("Order does not belong to customer");
|
|
320
|
+
}
|
|
321
|
+
if (order.paymentStatus === "paid") {
|
|
322
|
+
throw new Error("Cannot apply voucher to paid order");
|
|
323
|
+
}
|
|
324
|
+
// Get and validate voucher
|
|
325
|
+
const voucher = await ctx.db
|
|
326
|
+
.query("vouchers")
|
|
327
|
+
.withIndex("by_code", (q) => q.eq("code", args.voucherCode.toUpperCase()))
|
|
328
|
+
.first();
|
|
329
|
+
if (!voucher || voucher.isDeleted || !voucher.isActive) {
|
|
330
|
+
throw new Error("Voucher not found or inactive");
|
|
331
|
+
}
|
|
332
|
+
const now = getCurrentTimestamp();
|
|
333
|
+
// Check validity dates
|
|
334
|
+
if (voucher.validFrom && voucher.validFrom > now) {
|
|
335
|
+
throw new Error("Voucher is not yet valid");
|
|
336
|
+
}
|
|
337
|
+
if (voucher.validUntil && voucher.validUntil < now) {
|
|
338
|
+
throw new Error("Voucher has expired");
|
|
339
|
+
}
|
|
340
|
+
// Check usage limit
|
|
341
|
+
if (voucher.usedCount >= voucher.usageLimit) {
|
|
342
|
+
throw new Error("Voucher usage limit reached");
|
|
343
|
+
}
|
|
344
|
+
// Check per-customer limit
|
|
345
|
+
if (voucher.maxUsesPerCustomer) {
|
|
346
|
+
const customerUsages = await ctx.db
|
|
347
|
+
.query("voucherUsages")
|
|
348
|
+
.withIndex("by_customer", (q) => q.eq("customerId", order.customerId))
|
|
349
|
+
.filter((q) => q.eq(q.field("voucherId"), voucher._id))
|
|
350
|
+
.filter((q) => q.eq(q.field("isDeleted"), false))
|
|
351
|
+
.collect();
|
|
352
|
+
if (customerUsages.length >= voucher.maxUsesPerCustomer) {
|
|
353
|
+
throw new Error("You have reached the maximum uses for this voucher");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Check minimum order value
|
|
357
|
+
if (voucher.minOrderValue && order.totalPrice < voucher.minOrderValue) {
|
|
358
|
+
throw new Error(`Minimum order value of ₵${voucher.minOrderValue} required`);
|
|
359
|
+
}
|
|
360
|
+
// Check branch restriction
|
|
361
|
+
if (voucher.applicableBranches && voucher.applicableBranches.length > 0) {
|
|
362
|
+
if (!voucher.applicableBranches.includes(order.branchId)) {
|
|
363
|
+
throw new Error("Voucher not valid for this branch");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// Check service type restriction
|
|
367
|
+
if (voucher.applicableServiceTypes && voucher.applicableServiceTypes.length > 0) {
|
|
368
|
+
if (!voucher.applicableServiceTypes.includes(order.serviceType)) {
|
|
369
|
+
throw new Error("Voucher not valid for this service type");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// Calculate discount amount
|
|
373
|
+
let discountAmount = 0;
|
|
374
|
+
if (voucher.discountType === "percentage") {
|
|
375
|
+
discountAmount = (order.totalPrice * voucher.discountValue) / 100;
|
|
376
|
+
}
|
|
377
|
+
else if (voucher.discountType === "fixed") {
|
|
378
|
+
discountAmount = voucher.discountValue;
|
|
379
|
+
}
|
|
380
|
+
else if (voucher.discountType === "free_wash") {
|
|
381
|
+
discountAmount = order.totalPrice; // 100% discount
|
|
382
|
+
}
|
|
383
|
+
// Don't allow discount to exceed order total
|
|
384
|
+
discountAmount = Math.min(discountAmount, order.totalPrice);
|
|
385
|
+
discountAmount = Math.round(discountAmount * 100) / 100;
|
|
386
|
+
const finalPrice = Math.max(0, Math.round((order.totalPrice - discountAmount) * 100) / 100);
|
|
387
|
+
// Update order
|
|
388
|
+
await ctx.db.patch(args.orderId, {
|
|
389
|
+
finalPrice,
|
|
390
|
+
});
|
|
391
|
+
// Increment voucher usage count
|
|
392
|
+
await ctx.db.patch(voucher._id, {
|
|
393
|
+
usedCount: voucher.usedCount + 1,
|
|
394
|
+
});
|
|
395
|
+
// Create usage record
|
|
396
|
+
await ctx.db.insert("voucherUsages", {
|
|
397
|
+
voucherId: voucher._id,
|
|
398
|
+
orderId: args.orderId,
|
|
399
|
+
customerId: order.customerId,
|
|
400
|
+
discountAmount,
|
|
401
|
+
orderTotalBefore: order.totalPrice,
|
|
402
|
+
orderTotalAfter: finalPrice,
|
|
403
|
+
usedAt: now,
|
|
404
|
+
usedBy: attendant?._id,
|
|
405
|
+
isDeleted: false,
|
|
406
|
+
});
|
|
407
|
+
await createAuditLog({
|
|
408
|
+
ctx,
|
|
409
|
+
actorId: customer?._id || attendant?._id || "system",
|
|
410
|
+
actorType: customer ? "customer" : "attendant",
|
|
411
|
+
actorRole: customer ? "customer" : "attendant",
|
|
412
|
+
action: "voucher.applied",
|
|
413
|
+
entityType: "voucher",
|
|
414
|
+
entityId: voucher._id,
|
|
415
|
+
branchId: order.branchId,
|
|
416
|
+
details: JSON.stringify({
|
|
417
|
+
orderId: args.orderId,
|
|
418
|
+
discountAmount,
|
|
419
|
+
finalPrice,
|
|
420
|
+
}),
|
|
421
|
+
});
|
|
422
|
+
return {
|
|
423
|
+
voucherId: voucher._id,
|
|
424
|
+
discountAmount,
|
|
425
|
+
finalPrice,
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
/**
|
|
430
|
+
* Get voucher usage history (admin only)
|
|
431
|
+
*/
|
|
432
|
+
export const getUsageHistory = query({
|
|
433
|
+
args: {
|
|
434
|
+
voucherId: v.optional(v.id("vouchers")),
|
|
435
|
+
cursor: v.optional(v.string()),
|
|
436
|
+
numItems: v.optional(v.number()),
|
|
437
|
+
},
|
|
438
|
+
handler: async (ctx, args) => {
|
|
439
|
+
await getCurrentAdmin(ctx);
|
|
440
|
+
const numItems = args.numItems ?? 20;
|
|
441
|
+
let query;
|
|
442
|
+
if (args.voucherId) {
|
|
443
|
+
query = ctx.db
|
|
444
|
+
.query("voucherUsages")
|
|
445
|
+
.withIndex("by_voucher", (q) => q.eq("voucherId", args.voucherId));
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
query = ctx.db.query("voucherUsages");
|
|
449
|
+
}
|
|
450
|
+
const result = await query
|
|
451
|
+
.filter((q) => q.eq(q.field("isDeleted"), false))
|
|
452
|
+
.order("desc")
|
|
453
|
+
.paginate({
|
|
454
|
+
cursor: args.cursor ?? null,
|
|
455
|
+
numItems,
|
|
456
|
+
});
|
|
457
|
+
return {
|
|
458
|
+
page: result.page,
|
|
459
|
+
isDone: result.isDone,
|
|
460
|
+
continueCursor: result.continueCursor,
|
|
461
|
+
};
|
|
462
|
+
},
|
|
463
|
+
});
|
|
464
|
+
//# sourceMappingURL=vouchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vouchers.js","sourceRoot":"","sources":["../../convex/vouchers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,kBAAkB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;aAAM,CAAC;YACN,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACxC,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,KAAK;aACvB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC;aAChD,KAAK,CAAC,MAAM,CAAC;aACb,QAAQ,CAAC;YACR,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI;YAC3B,QAAQ;SACT,CAAC,CAAC;QAEL,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,cAAc,EAAE,MAAM,CAAC,cAAc;SACtC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Washlab Backend - Client Package
|
|
3
|
+
*
|
|
4
|
+
* This package provides type-safe access to the Washlab Convex backend API.
|
|
5
|
+
* See README.md for usage examples.
|
|
6
|
+
*/
|
|
7
|
+
export { api, internal, components } from "../convex/_generated/api.js";
|
|
8
|
+
export type { DataModel, Doc, Id, TableNames } from "../convex/_generated/dataModel.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGxE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Washlab Backend - Client Package
|
|
3
|
+
*
|
|
4
|
+
* This package provides type-safe access to the Washlab Convex backend API.
|
|
5
|
+
* See README.md for usage examples.
|
|
6
|
+
*/
|
|
7
|
+
// Re-export API runtime and types for client-side usage
|
|
8
|
+
export { api, internal, components } from "../convex/_generated/api.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wDAAwD;AACxD,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devlider001/washlab-backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Washlab backend - Convex API package for Lider Technology Ltd",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,9 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/lider-technology-ltd/washlab-backend#readme",
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "tsc --project tsconfig.build.json || exit 0",
|
|
37
|
+
"build": "tsc --project tsconfig.build.json >nul 2>&1 || exit 0",
|
|
38
|
+
"clean:convex": "node -e \"const fs=require('fs'),p=require('path');function rm(d){for(const f of fs.readdirSync(d)){const fp=p.join(d,f);const st=fs.statSync(fp);if(st.isDirectory()){if(f==='_generated')continue;rm(fp);}else{if(/\\.(?:js|js\\.map|d\\.ts|d\\.ts\\.map)$/.test(f)){fs.unlinkSync(fp);}}}}rm('convex');\"",
|
|
39
|
+
"prepack": "npm run clean:convex && npm run build",
|
|
38
40
|
"build:strict": "tsc --project tsconfig.build.json",
|
|
39
|
-
"prepublishOnly": "npm run build",
|
|
41
|
+
"prepublishOnly": "npm run clean:convex && npm run build",
|
|
40
42
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
41
43
|
},
|
|
42
44
|
"keywords": [
|
package/convex/_generated/api.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**
|
|
3
|
-
* Generated `api` utility.
|
|
4
|
-
*
|
|
5
|
-
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
-
*
|
|
7
|
-
* To regenerate, run `npx convex dev`.
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { anyApi, componentsGeneric } from "convex/server";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A utility for referencing Convex functions in your app's API.
|
|
15
|
-
*
|
|
16
|
-
* Usage:
|
|
17
|
-
* ```js
|
|
18
|
-
* const myFunctionReference = api.myModule.myFunction;
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const api = anyApi;
|
|
22
|
-
export const internal = anyApi;
|
|
23
|
-
export const components = componentsGeneric();
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**
|
|
3
|
-
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
-
*
|
|
5
|
-
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
-
*
|
|
7
|
-
* To regenerate, run `npx convex dev`.
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
actionGeneric,
|
|
13
|
-
httpActionGeneric,
|
|
14
|
-
queryGeneric,
|
|
15
|
-
mutationGeneric,
|
|
16
|
-
internalActionGeneric,
|
|
17
|
-
internalMutationGeneric,
|
|
18
|
-
internalQueryGeneric,
|
|
19
|
-
} from "convex/server";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Define a query in this Convex app's public API.
|
|
23
|
-
*
|
|
24
|
-
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
25
|
-
*
|
|
26
|
-
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
27
|
-
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
28
|
-
*/
|
|
29
|
-
export const query = queryGeneric;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
33
|
-
*
|
|
34
|
-
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
35
|
-
*
|
|
36
|
-
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
37
|
-
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
38
|
-
*/
|
|
39
|
-
export const internalQuery = internalQueryGeneric;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Define a mutation in this Convex app's public API.
|
|
43
|
-
*
|
|
44
|
-
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
45
|
-
*
|
|
46
|
-
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
47
|
-
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
48
|
-
*/
|
|
49
|
-
export const mutation = mutationGeneric;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
53
|
-
*
|
|
54
|
-
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
55
|
-
*
|
|
56
|
-
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
57
|
-
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
58
|
-
*/
|
|
59
|
-
export const internalMutation = internalMutationGeneric;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Define an action in this Convex app's public API.
|
|
63
|
-
*
|
|
64
|
-
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
65
|
-
* code and code with side-effects, like calling third-party services.
|
|
66
|
-
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
67
|
-
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
68
|
-
*
|
|
69
|
-
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
70
|
-
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
71
|
-
*/
|
|
72
|
-
export const action = actionGeneric;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
76
|
-
*
|
|
77
|
-
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
78
|
-
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
79
|
-
*/
|
|
80
|
-
export const internalAction = internalActionGeneric;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Define an HTTP action.
|
|
84
|
-
*
|
|
85
|
-
* The wrapped function will be used to respond to HTTP requests received
|
|
86
|
-
* by a Convex deployment if the requests matches the path and method where
|
|
87
|
-
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
|
|
88
|
-
*
|
|
89
|
-
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
90
|
-
* and a Fetch API `Request` object as its second.
|
|
91
|
-
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
92
|
-
*/
|
|
93
|
-
export const httpAction = httpActionGeneric;
|