mumz-strapi-plugin-coupon 1.0.7 → 1.1.0
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/content-types/coupon/index.d.ts +6 -0
- package/dist/content-types/coupon/schema.d.ts +6 -0
- package/dist/content-types/coupon/schema.js +15 -3
- package/dist/content-types/index.d.ts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/services/coupon.d.ts +6 -3
- package/dist/services/coupon.js +92 -59
- package/package.json +1 -1
|
@@ -21,8 +21,9 @@ exports.default = {
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
layouts: {
|
|
24
|
-
list: ['code', 'discountType', 'discountValue', 'currentUsage', 'maxUsage', 'isActive', 'validFrom', 'validTo'],
|
|
24
|
+
list: ['code', 'discountType', 'discountValue', 'currentUsage', 'maxUsage', 'maxUsagePerUser', 'isActive', 'validFrom', 'validTo'],
|
|
25
25
|
edit: [
|
|
26
|
+
// -- Coupon Info --
|
|
26
27
|
[
|
|
27
28
|
{ name: 'code', size: 6 },
|
|
28
29
|
{ name: 'isActive', size: 6 },
|
|
@@ -31,15 +32,20 @@ exports.default = {
|
|
|
31
32
|
{ name: 'discountType', size: 6 },
|
|
32
33
|
{ name: 'discountValue', size: 6 },
|
|
33
34
|
],
|
|
35
|
+
// -- Usage Limits --
|
|
34
36
|
[
|
|
35
|
-
{ name: 'maxUsage', size:
|
|
36
|
-
{ name: '
|
|
37
|
+
{ name: 'maxUsage', size: 4 },
|
|
38
|
+
{ name: 'maxUsagePerUser', size: 4 },
|
|
39
|
+
{ name: 'currentUsage', size: 4 },
|
|
37
40
|
],
|
|
41
|
+
// -- Validity Period --
|
|
38
42
|
[
|
|
39
43
|
{ name: 'validFrom', size: 6 },
|
|
40
44
|
{ name: 'validTo', size: 6 },
|
|
41
45
|
],
|
|
46
|
+
// -- Additional Info --
|
|
42
47
|
[{ name: 'description', size: 12 }],
|
|
48
|
+
// -- Restrictions --
|
|
43
49
|
[{ name: 'userRestrictions', size: 12 }],
|
|
44
50
|
],
|
|
45
51
|
},
|
|
@@ -67,6 +73,12 @@ exports.default = {
|
|
|
67
73
|
min: 0,
|
|
68
74
|
default: null,
|
|
69
75
|
},
|
|
76
|
+
maxUsagePerUser: {
|
|
77
|
+
type: 'integer',
|
|
78
|
+
required: false,
|
|
79
|
+
min: 0,
|
|
80
|
+
default: null,
|
|
81
|
+
},
|
|
70
82
|
currentUsage: {
|
|
71
83
|
type: 'integer',
|
|
72
84
|
required: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Core } from
|
|
1
|
+
import type { Core } from "@strapi/strapi";
|
|
2
2
|
export declare const ERROR_CODES: {
|
|
3
3
|
readonly COUPON_NOT_FOUND: "COUPON_NOT_FOUND";
|
|
4
4
|
readonly COUPON_EXPIRED: "COUPON_EXPIRED";
|
|
5
5
|
readonly COUPON_ALREADY_USED: "COUPON_ALREADY_USED";
|
|
6
6
|
readonly USAGE_LIMIT_REACHED: "USAGE_LIMIT_REACHED";
|
|
7
7
|
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
8
|
+
readonly USER_RESTRICTED: "USER_RESTRICTED";
|
|
8
9
|
};
|
|
9
10
|
export declare const ERROR_MESSAGES: {
|
|
10
11
|
readonly COUPON_NOT_FOUND: "Coupon code does not exist.";
|
|
@@ -12,6 +13,7 @@ export declare const ERROR_MESSAGES: {
|
|
|
12
13
|
readonly COUPON_ALREADY_USED: "This coupon has been already used.";
|
|
13
14
|
readonly USAGE_LIMIT_REACHED: "Coupon usage limit has been reached.";
|
|
14
15
|
readonly INVALID_REQUEST: "Invalid request parameters.";
|
|
16
|
+
readonly USER_RESTRICTED: "This coupon is not available for your phone number.";
|
|
15
17
|
};
|
|
16
18
|
export interface ValidateCouponRequest {
|
|
17
19
|
couponCode: string;
|
|
@@ -26,13 +28,14 @@ export interface RedeemCouponRequest {
|
|
|
26
28
|
}
|
|
27
29
|
export interface CreateCouponRequest {
|
|
28
30
|
code: string;
|
|
29
|
-
discountType:
|
|
31
|
+
discountType: "percentage" | "flat";
|
|
30
32
|
discountValue: number;
|
|
31
33
|
maxUsage?: number;
|
|
34
|
+
maxUsagePerUser?: number;
|
|
32
35
|
validFrom: string;
|
|
33
36
|
validTo: string;
|
|
34
37
|
description?: string;
|
|
35
|
-
userRestrictions?:
|
|
38
|
+
userRestrictions?: string[];
|
|
36
39
|
}
|
|
37
40
|
export interface ValidationResponse {
|
|
38
41
|
isValid: boolean;
|
package/dist/services/coupon.js
CHANGED
|
@@ -4,18 +4,20 @@ exports.ERROR_MESSAGES = exports.ERROR_CODES = void 0;
|
|
|
4
4
|
const validators_1 = require("../utils/validators");
|
|
5
5
|
// Error codes as per specification
|
|
6
6
|
exports.ERROR_CODES = {
|
|
7
|
-
COUPON_NOT_FOUND:
|
|
8
|
-
COUPON_EXPIRED:
|
|
9
|
-
COUPON_ALREADY_USED:
|
|
10
|
-
USAGE_LIMIT_REACHED:
|
|
11
|
-
INVALID_REQUEST:
|
|
7
|
+
COUPON_NOT_FOUND: "COUPON_NOT_FOUND",
|
|
8
|
+
COUPON_EXPIRED: "COUPON_EXPIRED",
|
|
9
|
+
COUPON_ALREADY_USED: "COUPON_ALREADY_USED",
|
|
10
|
+
USAGE_LIMIT_REACHED: "USAGE_LIMIT_REACHED",
|
|
11
|
+
INVALID_REQUEST: "INVALID_REQUEST",
|
|
12
|
+
USER_RESTRICTED: "USER_RESTRICTED",
|
|
12
13
|
};
|
|
13
14
|
exports.ERROR_MESSAGES = {
|
|
14
|
-
COUPON_NOT_FOUND:
|
|
15
|
-
COUPON_EXPIRED:
|
|
16
|
-
COUPON_ALREADY_USED:
|
|
17
|
-
USAGE_LIMIT_REACHED:
|
|
18
|
-
INVALID_REQUEST:
|
|
15
|
+
COUPON_NOT_FOUND: "Coupon code does not exist.",
|
|
16
|
+
COUPON_EXPIRED: "This coupon has expired.",
|
|
17
|
+
COUPON_ALREADY_USED: "This coupon has been already used.",
|
|
18
|
+
USAGE_LIMIT_REACHED: "Coupon usage limit has been reached.",
|
|
19
|
+
INVALID_REQUEST: "Invalid request parameters.",
|
|
20
|
+
USER_RESTRICTED: "This coupon is not available for your phone number.",
|
|
19
21
|
};
|
|
20
22
|
const couponService = ({ strapi }) => ({
|
|
21
23
|
/**
|
|
@@ -29,25 +31,25 @@ const couponService = ({ strapi }) => ({
|
|
|
29
31
|
return {
|
|
30
32
|
isValid: false,
|
|
31
33
|
errorCode: exports.ERROR_CODES.INVALID_REQUEST,
|
|
32
|
-
message:
|
|
34
|
+
message: "Invalid coupon code format",
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
if (!(0, validators_1.validatePhoneNumber)(phoneNumber)) {
|
|
36
38
|
return {
|
|
37
39
|
isValid: false,
|
|
38
40
|
errorCode: exports.ERROR_CODES.INVALID_REQUEST,
|
|
39
|
-
message:
|
|
41
|
+
message: "Invalid phone number format",
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
if (orderAmount < 0) {
|
|
43
45
|
return {
|
|
44
46
|
isValid: false,
|
|
45
47
|
errorCode: exports.ERROR_CODES.INVALID_REQUEST,
|
|
46
|
-
message:
|
|
48
|
+
message: "Order amount cannot be negative",
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
// Find the coupon by code
|
|
50
|
-
const coupons = await strapi.entityService.findMany(
|
|
52
|
+
const coupons = await strapi.entityService.findMany("plugin::coupon.coupon", {
|
|
51
53
|
filters: {
|
|
52
54
|
code: couponCode,
|
|
53
55
|
},
|
|
@@ -88,14 +90,19 @@ const couponService = ({ strapi }) => ({
|
|
|
88
90
|
message: exports.ERROR_MESSAGES.USAGE_LIMIT_REACHED,
|
|
89
91
|
};
|
|
90
92
|
}
|
|
91
|
-
// Check
|
|
92
|
-
const existingRedemptions = await strapi.entityService.findMany(
|
|
93
|
+
// Check per-user usage limit
|
|
94
|
+
const existingRedemptions = await strapi.entityService.findMany("plugin::coupon.redemption", {
|
|
93
95
|
filters: {
|
|
94
96
|
coupon: coupon.id,
|
|
95
97
|
phoneNumber,
|
|
96
98
|
},
|
|
97
99
|
});
|
|
98
|
-
|
|
100
|
+
const userRedemptionCount = Array.isArray(existingRedemptions)
|
|
101
|
+
? existingRedemptions.length
|
|
102
|
+
: 0;
|
|
103
|
+
// maxUsagePerUser: 0 = disabled, null/undefined = 1, N = N uses per user
|
|
104
|
+
const perUserLimit = coupon.maxUsagePerUser ?? 1;
|
|
105
|
+
if (perUserLimit === 0 || userRedemptionCount >= perUserLimit) {
|
|
99
106
|
return {
|
|
100
107
|
isValid: false,
|
|
101
108
|
errorCode: exports.ERROR_CODES.COUPON_ALREADY_USED,
|
|
@@ -105,11 +112,11 @@ const couponService = ({ strapi }) => ({
|
|
|
105
112
|
// Calculate discount
|
|
106
113
|
let discountAmount = 0;
|
|
107
114
|
let finalAmount = orderAmount;
|
|
108
|
-
if (coupon.discountType ===
|
|
115
|
+
if (coupon.discountType === "percentage") {
|
|
109
116
|
discountAmount = (orderAmount * coupon.discountValue) / 100;
|
|
110
117
|
finalAmount = orderAmount - discountAmount;
|
|
111
118
|
}
|
|
112
|
-
else if (coupon.discountType ===
|
|
119
|
+
else if (coupon.discountType === "flat") {
|
|
113
120
|
discountAmount = coupon.discountValue;
|
|
114
121
|
finalAmount = Math.max(0, orderAmount - discountAmount);
|
|
115
122
|
}
|
|
@@ -120,11 +127,11 @@ const couponService = ({ strapi }) => ({
|
|
|
120
127
|
discountValue: coupon.discountValue,
|
|
121
128
|
discountAmount,
|
|
122
129
|
finalAmount,
|
|
123
|
-
message:
|
|
130
|
+
message: "Coupon applied successfully.",
|
|
124
131
|
};
|
|
125
132
|
}
|
|
126
133
|
catch (error) {
|
|
127
|
-
strapi.log.error(
|
|
134
|
+
strapi.log.error("Error validating coupon:", error);
|
|
128
135
|
throw error;
|
|
129
136
|
}
|
|
130
137
|
},
|
|
@@ -140,11 +147,11 @@ const couponService = ({ strapi }) => ({
|
|
|
140
147
|
return {
|
|
141
148
|
success: false,
|
|
142
149
|
errorCode: exports.ERROR_CODES.INVALID_REQUEST,
|
|
143
|
-
message:
|
|
150
|
+
message: "Invalid order ID format",
|
|
144
151
|
};
|
|
145
152
|
}
|
|
146
153
|
// Find and validate the coupon
|
|
147
|
-
const coupons = await strapi.db.query(
|
|
154
|
+
const coupons = await strapi.db.query("plugin::coupon.coupon").findMany({
|
|
148
155
|
where: { code: couponCode },
|
|
149
156
|
});
|
|
150
157
|
const coupon = Array.isArray(coupons) && coupons.length > 0 ? coupons[0] : null;
|
|
@@ -160,7 +167,7 @@ const couponService = ({ strapi }) => ({
|
|
|
160
167
|
return {
|
|
161
168
|
success: false,
|
|
162
169
|
errorCode: exports.ERROR_CODES.INVALID_REQUEST,
|
|
163
|
-
message:
|
|
170
|
+
message: "Invalid phone number format",
|
|
164
171
|
};
|
|
165
172
|
}
|
|
166
173
|
// Perform all validations
|
|
@@ -181,14 +188,31 @@ const couponService = ({ strapi }) => ({
|
|
|
181
188
|
message: exports.ERROR_MESSAGES.COUPON_EXPIRED,
|
|
182
189
|
};
|
|
183
190
|
}
|
|
184
|
-
// Check
|
|
185
|
-
|
|
191
|
+
// Check user restrictions (blocked phone numbers)
|
|
192
|
+
if (coupon.userRestrictions && Array.isArray(coupon.userRestrictions)) {
|
|
193
|
+
if (coupon.userRestrictions.includes(phoneNumber)) {
|
|
194
|
+
return {
|
|
195
|
+
success: false,
|
|
196
|
+
errorCode: exports.ERROR_CODES.USER_RESTRICTED,
|
|
197
|
+
message: exports.ERROR_MESSAGES.USER_RESTRICTED,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Check per-user usage limit
|
|
202
|
+
const existingRedemptions = await strapi.db
|
|
203
|
+
.query("plugin::coupon.redemption")
|
|
204
|
+
.findMany({
|
|
186
205
|
where: {
|
|
187
206
|
coupon: coupon.id,
|
|
188
207
|
phoneNumber,
|
|
189
208
|
},
|
|
190
209
|
});
|
|
191
|
-
|
|
210
|
+
const userRedemptionCount = Array.isArray(existingRedemptions)
|
|
211
|
+
? existingRedemptions.length
|
|
212
|
+
: 0;
|
|
213
|
+
// maxUsagePerUser: 0 = disabled, null/undefined = 1, N = N uses per user
|
|
214
|
+
const perUserLimit = coupon.maxUsagePerUser ?? 1;
|
|
215
|
+
if (perUserLimit === 0 || userRedemptionCount >= perUserLimit) {
|
|
192
216
|
return {
|
|
193
217
|
success: false,
|
|
194
218
|
errorCode: exports.ERROR_CODES.COUPON_ALREADY_USED,
|
|
@@ -206,11 +230,11 @@ const couponService = ({ strapi }) => ({
|
|
|
206
230
|
// Calculate discount
|
|
207
231
|
let discountAmount = 0;
|
|
208
232
|
let finalAmount = orderAmount;
|
|
209
|
-
if (coupon.discountType ===
|
|
233
|
+
if (coupon.discountType === "percentage") {
|
|
210
234
|
discountAmount = (orderAmount * coupon.discountValue) / 100;
|
|
211
235
|
finalAmount = orderAmount - discountAmount;
|
|
212
236
|
}
|
|
213
|
-
else if (coupon.discountType ===
|
|
237
|
+
else if (coupon.discountType === "flat") {
|
|
214
238
|
discountAmount = coupon.discountValue;
|
|
215
239
|
finalAmount = Math.max(0, orderAmount - discountAmount);
|
|
216
240
|
}
|
|
@@ -218,7 +242,9 @@ const couponService = ({ strapi }) => ({
|
|
|
218
242
|
let redemptionId;
|
|
219
243
|
try {
|
|
220
244
|
// Atomic increment with optimistic locking
|
|
221
|
-
const updateResult = await strapi.db
|
|
245
|
+
const updateResult = await strapi.db
|
|
246
|
+
.query("plugin::coupon.coupon")
|
|
247
|
+
.update({
|
|
222
248
|
where: {
|
|
223
249
|
id: coupon.id,
|
|
224
250
|
currentUsage: coupon.currentUsage, // Optimistic lock
|
|
@@ -228,7 +254,8 @@ const couponService = ({ strapi }) => ({
|
|
|
228
254
|
},
|
|
229
255
|
});
|
|
230
256
|
// If update failed due to concurrent modification, check usage limit
|
|
231
|
-
if (!updateResult ||
|
|
257
|
+
if (!updateResult ||
|
|
258
|
+
(coupon.maxUsage && coupon.currentUsage + 1 > coupon.maxUsage)) {
|
|
232
259
|
return {
|
|
233
260
|
success: false,
|
|
234
261
|
errorCode: exports.ERROR_CODES.USAGE_LIMIT_REACHED,
|
|
@@ -236,7 +263,9 @@ const couponService = ({ strapi }) => ({
|
|
|
236
263
|
};
|
|
237
264
|
}
|
|
238
265
|
// Create redemption record
|
|
239
|
-
const redemption = await strapi.db
|
|
266
|
+
const redemption = await strapi.db
|
|
267
|
+
.query("plugin::coupon.redemption")
|
|
268
|
+
.create({
|
|
240
269
|
data: {
|
|
241
270
|
coupon: coupon.id,
|
|
242
271
|
phoneNumber,
|
|
@@ -254,17 +283,17 @@ const couponService = ({ strapi }) => ({
|
|
|
254
283
|
redemptionId = `redeem_${redemption.id}`;
|
|
255
284
|
}
|
|
256
285
|
catch (error) {
|
|
257
|
-
strapi.log.error(
|
|
286
|
+
strapi.log.error("Transaction error during redemption:", error);
|
|
258
287
|
throw error;
|
|
259
288
|
}
|
|
260
289
|
return {
|
|
261
290
|
success: true,
|
|
262
|
-
message:
|
|
291
|
+
message: "Coupon redeemed successfully.",
|
|
263
292
|
redemptionId,
|
|
264
293
|
};
|
|
265
294
|
}
|
|
266
295
|
catch (error) {
|
|
267
|
-
strapi.log.error(
|
|
296
|
+
strapi.log.error("Error redeeming coupon:", error);
|
|
268
297
|
throw error;
|
|
269
298
|
}
|
|
270
299
|
},
|
|
@@ -273,13 +302,13 @@ const couponService = ({ strapi }) => ({
|
|
|
273
302
|
*/
|
|
274
303
|
async create(params) {
|
|
275
304
|
try {
|
|
276
|
-
const { code, discountType, discountValue, maxUsage, validFrom, validTo, description, userRestrictions, } = params;
|
|
305
|
+
const { code, discountType, discountValue, maxUsage, maxUsagePerUser, validFrom, validTo, description, userRestrictions, } = params;
|
|
277
306
|
// Validate coupon code
|
|
278
307
|
if (!(0, validators_1.validateCouponCode)(code)) {
|
|
279
308
|
return {
|
|
280
309
|
success: false,
|
|
281
|
-
errorCode:
|
|
282
|
-
message:
|
|
310
|
+
errorCode: "INVALID_COUPON_CODE",
|
|
311
|
+
message: "Coupon code must be 3-50 uppercase alphanumeric characters",
|
|
283
312
|
};
|
|
284
313
|
}
|
|
285
314
|
// Validate discount value
|
|
@@ -287,8 +316,8 @@ const couponService = ({ strapi }) => ({
|
|
|
287
316
|
if (!discountValidation.valid) {
|
|
288
317
|
return {
|
|
289
318
|
success: false,
|
|
290
|
-
errorCode:
|
|
291
|
-
message: discountValidation.error ||
|
|
319
|
+
errorCode: "INVALID_DISCOUNT",
|
|
320
|
+
message: discountValidation.error || "Invalid discount value",
|
|
292
321
|
};
|
|
293
322
|
}
|
|
294
323
|
// Validate date range
|
|
@@ -296,20 +325,21 @@ const couponService = ({ strapi }) => ({
|
|
|
296
325
|
if (!dateValidation.valid) {
|
|
297
326
|
return {
|
|
298
327
|
success: false,
|
|
299
|
-
errorCode:
|
|
300
|
-
message: dateValidation.error ||
|
|
328
|
+
errorCode: "INVALID_DATE_RANGE",
|
|
329
|
+
message: dateValidation.error || "Invalid date range",
|
|
301
330
|
};
|
|
302
331
|
}
|
|
303
332
|
// Validate maxUsage
|
|
304
|
-
if (maxUsage !== undefined &&
|
|
333
|
+
if (maxUsage !== undefined &&
|
|
334
|
+
(typeof maxUsage !== "number" || maxUsage < 1)) {
|
|
305
335
|
return {
|
|
306
336
|
success: false,
|
|
307
|
-
errorCode:
|
|
308
|
-
message:
|
|
337
|
+
errorCode: "INVALID_MAX_USAGE",
|
|
338
|
+
message: "maxUsage must be a positive number",
|
|
309
339
|
};
|
|
310
340
|
}
|
|
311
341
|
// Check if coupon code already exists
|
|
312
|
-
const existingCoupons = await strapi.entityService.findMany(
|
|
342
|
+
const existingCoupons = await strapi.entityService.findMany("plugin::coupon.coupon", {
|
|
313
343
|
filters: {
|
|
314
344
|
code,
|
|
315
345
|
},
|
|
@@ -317,17 +347,18 @@ const couponService = ({ strapi }) => ({
|
|
|
317
347
|
if (Array.isArray(existingCoupons) && existingCoupons.length > 0) {
|
|
318
348
|
return {
|
|
319
349
|
success: false,
|
|
320
|
-
errorCode:
|
|
321
|
-
message:
|
|
350
|
+
errorCode: "COUPON_ALREADY_EXISTS",
|
|
351
|
+
message: "A coupon with this code already exists.",
|
|
322
352
|
};
|
|
323
353
|
}
|
|
324
354
|
// Create the coupon
|
|
325
|
-
const coupon = await strapi.entityService.create(
|
|
355
|
+
const coupon = await strapi.entityService.create("plugin::coupon.coupon", {
|
|
326
356
|
data: {
|
|
327
357
|
code,
|
|
328
358
|
discountType,
|
|
329
359
|
discountValue,
|
|
330
360
|
maxUsage: maxUsage || null,
|
|
361
|
+
maxUsagePerUser: maxUsagePerUser ?? null,
|
|
331
362
|
currentUsage: 0,
|
|
332
363
|
validFrom,
|
|
333
364
|
validTo,
|
|
@@ -339,11 +370,11 @@ const couponService = ({ strapi }) => ({
|
|
|
339
370
|
return {
|
|
340
371
|
success: true,
|
|
341
372
|
couponId: `coupon_${coupon.id}`,
|
|
342
|
-
message:
|
|
373
|
+
message: "Coupon created successfully.",
|
|
343
374
|
};
|
|
344
375
|
}
|
|
345
376
|
catch (error) {
|
|
346
|
-
strapi.log.error(
|
|
377
|
+
strapi.log.error("Error creating coupon:", error);
|
|
347
378
|
throw error;
|
|
348
379
|
}
|
|
349
380
|
},
|
|
@@ -352,10 +383,10 @@ const couponService = ({ strapi }) => ({
|
|
|
352
383
|
*/
|
|
353
384
|
async findAll(query = {}) {
|
|
354
385
|
try {
|
|
355
|
-
return await strapi.entityService.findMany(
|
|
386
|
+
return await strapi.entityService.findMany("plugin::coupon.coupon", query);
|
|
356
387
|
}
|
|
357
388
|
catch (error) {
|
|
358
|
-
strapi.log.error(
|
|
389
|
+
strapi.log.error("Error finding coupons:", error);
|
|
359
390
|
throw error;
|
|
360
391
|
}
|
|
361
392
|
},
|
|
@@ -364,10 +395,10 @@ const couponService = ({ strapi }) => ({
|
|
|
364
395
|
*/
|
|
365
396
|
async findOne(id) {
|
|
366
397
|
try {
|
|
367
|
-
return await strapi.entityService.findOne(
|
|
398
|
+
return await strapi.entityService.findOne("plugin::coupon.coupon", id);
|
|
368
399
|
}
|
|
369
400
|
catch (error) {
|
|
370
|
-
strapi.log.error(
|
|
401
|
+
strapi.log.error("Error finding coupon:", error);
|
|
371
402
|
throw error;
|
|
372
403
|
}
|
|
373
404
|
},
|
|
@@ -376,10 +407,12 @@ const couponService = ({ strapi }) => ({
|
|
|
376
407
|
*/
|
|
377
408
|
async update(id, data) {
|
|
378
409
|
try {
|
|
379
|
-
return await strapi.entityService.update(
|
|
410
|
+
return await strapi.entityService.update("plugin::coupon.coupon", id, {
|
|
411
|
+
data,
|
|
412
|
+
});
|
|
380
413
|
}
|
|
381
414
|
catch (error) {
|
|
382
|
-
strapi.log.error(
|
|
415
|
+
strapi.log.error("Error updating coupon:", error);
|
|
383
416
|
throw error;
|
|
384
417
|
}
|
|
385
418
|
},
|
|
@@ -388,10 +421,10 @@ const couponService = ({ strapi }) => ({
|
|
|
388
421
|
*/
|
|
389
422
|
async delete(id) {
|
|
390
423
|
try {
|
|
391
|
-
return await strapi.entityService.delete(
|
|
424
|
+
return await strapi.entityService.delete("plugin::coupon.coupon", id);
|
|
392
425
|
}
|
|
393
426
|
catch (error) {
|
|
394
|
-
strapi.log.error(
|
|
427
|
+
strapi.log.error("Error deleting coupon:", error);
|
|
395
428
|
throw error;
|
|
396
429
|
}
|
|
397
430
|
},
|