mumz-strapi-plugin-coupon 1.0.7
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/README.md +311 -0
- package/dist/bootstrap.d.ts +5 -0
- package/dist/bootstrap.js +6 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +6 -0
- package/dist/content-types/coupon/index.d.ts +90 -0
- package/dist/content-types/coupon/index.js +9 -0
- package/dist/content-types/coupon/schema.d.ts +88 -0
- package/dist/content-types/coupon/schema.js +105 -0
- package/dist/content-types/index.d.ts +155 -0
- package/dist/content-types/index.js +11 -0
- package/dist/content-types/redemption/index.d.ts +64 -0
- package/dist/content-types/redemption/index.js +9 -0
- package/dist/content-types/redemption/schema.d.ts +62 -0
- package/dist/content-types/redemption/schema.js +74 -0
- package/dist/controllers/coupon.d.ts +41 -0
- package/dist/controllers/coupon.js +154 -0
- package/dist/controllers/index.d.ts +5 -0
- package/dist/controllers/index.js +9 -0
- package/dist/destroy.d.ts +5 -0
- package/dist/destroy.js +6 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +24 -0
- package/dist/middlewares/index.d.ts +4 -0
- package/dist/middlewares/index.js +9 -0
- package/dist/middlewares/rate-limit.d.ts +6 -0
- package/dist/middlewares/rate-limit.js +42 -0
- package/dist/register.d.ts +5 -0
- package/dist/register.js +6 -0
- package/dist/routes/content-api/index.d.ts +23 -0
- package/dist/routes/content-api/index.js +76 -0
- package/dist/routes/index.d.ts +25 -0
- package/dist/routes/index.js +9 -0
- package/dist/services/coupon.d.ts +61 -0
- package/dist/services/coupon.js +399 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.js +9 -0
- package/dist/utils/validators.d.ts +14 -0
- package/dist/utils/validators.js +41 -0
- package/package.json +71 -0
- package/strapi-server.js +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
coupon: {
|
|
3
|
+
schema: {
|
|
4
|
+
kind: string;
|
|
5
|
+
collectionName: string;
|
|
6
|
+
info: {
|
|
7
|
+
singularName: string;
|
|
8
|
+
pluralName: string;
|
|
9
|
+
displayName: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
options: {
|
|
13
|
+
draftAndPublish: boolean;
|
|
14
|
+
};
|
|
15
|
+
pluginOptions: {
|
|
16
|
+
'content-manager': {
|
|
17
|
+
visible: boolean;
|
|
18
|
+
};
|
|
19
|
+
'content-type-builder': {
|
|
20
|
+
visible: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
layouts: {
|
|
24
|
+
list: string[];
|
|
25
|
+
edit: {
|
|
26
|
+
name: string;
|
|
27
|
+
size: number;
|
|
28
|
+
}[][];
|
|
29
|
+
};
|
|
30
|
+
attributes: {
|
|
31
|
+
code: {
|
|
32
|
+
type: string;
|
|
33
|
+
required: boolean;
|
|
34
|
+
unique: boolean;
|
|
35
|
+
configurable: boolean;
|
|
36
|
+
};
|
|
37
|
+
discountType: {
|
|
38
|
+
type: string;
|
|
39
|
+
enum: string[];
|
|
40
|
+
required: boolean;
|
|
41
|
+
default: string;
|
|
42
|
+
};
|
|
43
|
+
discountValue: {
|
|
44
|
+
type: string;
|
|
45
|
+
required: boolean;
|
|
46
|
+
min: number;
|
|
47
|
+
};
|
|
48
|
+
maxUsage: {
|
|
49
|
+
type: string;
|
|
50
|
+
required: boolean;
|
|
51
|
+
min: number;
|
|
52
|
+
default: null;
|
|
53
|
+
};
|
|
54
|
+
currentUsage: {
|
|
55
|
+
type: string;
|
|
56
|
+
required: boolean;
|
|
57
|
+
default: number;
|
|
58
|
+
min: number;
|
|
59
|
+
};
|
|
60
|
+
validFrom: {
|
|
61
|
+
type: string;
|
|
62
|
+
required: boolean;
|
|
63
|
+
};
|
|
64
|
+
validTo: {
|
|
65
|
+
type: string;
|
|
66
|
+
required: boolean;
|
|
67
|
+
};
|
|
68
|
+
isActive: {
|
|
69
|
+
type: string;
|
|
70
|
+
default: boolean;
|
|
71
|
+
required: boolean;
|
|
72
|
+
};
|
|
73
|
+
description: {
|
|
74
|
+
type: string;
|
|
75
|
+
required: boolean;
|
|
76
|
+
};
|
|
77
|
+
userRestrictions: {
|
|
78
|
+
type: string;
|
|
79
|
+
required: boolean;
|
|
80
|
+
default: null;
|
|
81
|
+
};
|
|
82
|
+
redemptions: {
|
|
83
|
+
type: string;
|
|
84
|
+
relation: string;
|
|
85
|
+
target: string;
|
|
86
|
+
mappedBy: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
redemption: {
|
|
92
|
+
schema: {
|
|
93
|
+
kind: string;
|
|
94
|
+
collectionName: string;
|
|
95
|
+
info: {
|
|
96
|
+
singularName: string;
|
|
97
|
+
pluralName: string;
|
|
98
|
+
displayName: string;
|
|
99
|
+
description: string;
|
|
100
|
+
};
|
|
101
|
+
options: {
|
|
102
|
+
draftAndPublish: boolean;
|
|
103
|
+
};
|
|
104
|
+
pluginOptions: {
|
|
105
|
+
'content-manager': {
|
|
106
|
+
visible: boolean;
|
|
107
|
+
};
|
|
108
|
+
'content-type-builder': {
|
|
109
|
+
visible: boolean;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
layouts: {
|
|
113
|
+
list: string[];
|
|
114
|
+
edit: {
|
|
115
|
+
name: string;
|
|
116
|
+
size: number;
|
|
117
|
+
}[][];
|
|
118
|
+
};
|
|
119
|
+
attributes: {
|
|
120
|
+
coupon: {
|
|
121
|
+
type: string;
|
|
122
|
+
relation: string;
|
|
123
|
+
target: string;
|
|
124
|
+
inversedBy: string;
|
|
125
|
+
};
|
|
126
|
+
orderId: {
|
|
127
|
+
type: string;
|
|
128
|
+
required: boolean;
|
|
129
|
+
};
|
|
130
|
+
phoneNumber: {
|
|
131
|
+
type: string;
|
|
132
|
+
required: boolean;
|
|
133
|
+
};
|
|
134
|
+
redemptionDate: {
|
|
135
|
+
type: string;
|
|
136
|
+
required: boolean;
|
|
137
|
+
};
|
|
138
|
+
discountType: {
|
|
139
|
+
type: string;
|
|
140
|
+
required: boolean;
|
|
141
|
+
};
|
|
142
|
+
discountValue: {
|
|
143
|
+
type: string;
|
|
144
|
+
required: boolean;
|
|
145
|
+
};
|
|
146
|
+
metadata: {
|
|
147
|
+
type: string;
|
|
148
|
+
required: boolean;
|
|
149
|
+
default: null;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const coupon_1 = __importDefault(require("./coupon"));
|
|
7
|
+
const redemption_1 = __importDefault(require("./redemption"));
|
|
8
|
+
exports.default = {
|
|
9
|
+
coupon: coupon_1.default,
|
|
10
|
+
redemption: redemption_1.default,
|
|
11
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
schema: {
|
|
3
|
+
kind: string;
|
|
4
|
+
collectionName: string;
|
|
5
|
+
info: {
|
|
6
|
+
singularName: string;
|
|
7
|
+
pluralName: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
options: {
|
|
12
|
+
draftAndPublish: boolean;
|
|
13
|
+
};
|
|
14
|
+
pluginOptions: {
|
|
15
|
+
'content-manager': {
|
|
16
|
+
visible: boolean;
|
|
17
|
+
};
|
|
18
|
+
'content-type-builder': {
|
|
19
|
+
visible: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
layouts: {
|
|
23
|
+
list: string[];
|
|
24
|
+
edit: {
|
|
25
|
+
name: string;
|
|
26
|
+
size: number;
|
|
27
|
+
}[][];
|
|
28
|
+
};
|
|
29
|
+
attributes: {
|
|
30
|
+
coupon: {
|
|
31
|
+
type: string;
|
|
32
|
+
relation: string;
|
|
33
|
+
target: string;
|
|
34
|
+
inversedBy: string;
|
|
35
|
+
};
|
|
36
|
+
orderId: {
|
|
37
|
+
type: string;
|
|
38
|
+
required: boolean;
|
|
39
|
+
};
|
|
40
|
+
phoneNumber: {
|
|
41
|
+
type: string;
|
|
42
|
+
required: boolean;
|
|
43
|
+
};
|
|
44
|
+
redemptionDate: {
|
|
45
|
+
type: string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
};
|
|
48
|
+
discountType: {
|
|
49
|
+
type: string;
|
|
50
|
+
required: boolean;
|
|
51
|
+
};
|
|
52
|
+
discountValue: {
|
|
53
|
+
type: string;
|
|
54
|
+
required: boolean;
|
|
55
|
+
};
|
|
56
|
+
metadata: {
|
|
57
|
+
type: string;
|
|
58
|
+
required: boolean;
|
|
59
|
+
default: null;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const schema_1 = __importDefault(require("./schema"));
|
|
7
|
+
exports.default = {
|
|
8
|
+
schema: schema_1.default,
|
|
9
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
kind: string;
|
|
3
|
+
collectionName: string;
|
|
4
|
+
info: {
|
|
5
|
+
singularName: string;
|
|
6
|
+
pluralName: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
description: string;
|
|
9
|
+
};
|
|
10
|
+
options: {
|
|
11
|
+
draftAndPublish: boolean;
|
|
12
|
+
};
|
|
13
|
+
pluginOptions: {
|
|
14
|
+
'content-manager': {
|
|
15
|
+
visible: boolean;
|
|
16
|
+
};
|
|
17
|
+
'content-type-builder': {
|
|
18
|
+
visible: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
layouts: {
|
|
22
|
+
list: string[];
|
|
23
|
+
edit: {
|
|
24
|
+
name: string;
|
|
25
|
+
size: number;
|
|
26
|
+
}[][];
|
|
27
|
+
};
|
|
28
|
+
attributes: {
|
|
29
|
+
coupon: {
|
|
30
|
+
type: string;
|
|
31
|
+
relation: string;
|
|
32
|
+
target: string;
|
|
33
|
+
inversedBy: string;
|
|
34
|
+
};
|
|
35
|
+
orderId: {
|
|
36
|
+
type: string;
|
|
37
|
+
required: boolean;
|
|
38
|
+
};
|
|
39
|
+
phoneNumber: {
|
|
40
|
+
type: string;
|
|
41
|
+
required: boolean;
|
|
42
|
+
};
|
|
43
|
+
redemptionDate: {
|
|
44
|
+
type: string;
|
|
45
|
+
required: boolean;
|
|
46
|
+
};
|
|
47
|
+
discountType: {
|
|
48
|
+
type: string;
|
|
49
|
+
required: boolean;
|
|
50
|
+
};
|
|
51
|
+
discountValue: {
|
|
52
|
+
type: string;
|
|
53
|
+
required: boolean;
|
|
54
|
+
};
|
|
55
|
+
metadata: {
|
|
56
|
+
type: string;
|
|
57
|
+
required: boolean;
|
|
58
|
+
default: null;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export default _default;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
kind: 'collectionType',
|
|
5
|
+
collectionName: 'coupon_redemptions',
|
|
6
|
+
info: {
|
|
7
|
+
singularName: 'redemption',
|
|
8
|
+
pluralName: 'redemptions',
|
|
9
|
+
displayName: 'Coupon Redemption',
|
|
10
|
+
description: 'Tracks coupon redemptions for audit trail',
|
|
11
|
+
},
|
|
12
|
+
options: {
|
|
13
|
+
draftAndPublish: false,
|
|
14
|
+
},
|
|
15
|
+
pluginOptions: {
|
|
16
|
+
'content-manager': {
|
|
17
|
+
visible: true,
|
|
18
|
+
},
|
|
19
|
+
'content-type-builder': {
|
|
20
|
+
visible: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
layouts: {
|
|
24
|
+
list: ['orderId', 'phoneNumber', 'redemptionDate', 'coupon'],
|
|
25
|
+
edit: [
|
|
26
|
+
[
|
|
27
|
+
{ name: 'orderId', size: 6 },
|
|
28
|
+
{ name: 'phoneNumber', size: 6 },
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
{ name: 'redemptionDate', size: 6 },
|
|
32
|
+
{ name: 'coupon', size: 6 },
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
{ name: 'discountType', size: 6 },
|
|
36
|
+
{ name: 'discountValue', size: 6 },
|
|
37
|
+
],
|
|
38
|
+
[{ name: 'metadata', size: 12 }],
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
attributes: {
|
|
42
|
+
coupon: {
|
|
43
|
+
type: 'relation',
|
|
44
|
+
relation: 'manyToOne',
|
|
45
|
+
target: 'plugin::coupon.coupon',
|
|
46
|
+
inversedBy: 'redemptions',
|
|
47
|
+
},
|
|
48
|
+
orderId: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
phoneNumber: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
redemptionDate: {
|
|
57
|
+
type: 'datetime',
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
discountType: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
required: true,
|
|
63
|
+
},
|
|
64
|
+
discountValue: {
|
|
65
|
+
type: 'decimal',
|
|
66
|
+
required: true,
|
|
67
|
+
},
|
|
68
|
+
metadata: {
|
|
69
|
+
type: 'json',
|
|
70
|
+
required: false,
|
|
71
|
+
default: null,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Core } from '@strapi/strapi';
|
|
2
|
+
declare const _default: ({ strapi }: {
|
|
3
|
+
strapi: Core.Strapi;
|
|
4
|
+
}) => {
|
|
5
|
+
/**
|
|
6
|
+
* Validate coupon endpoint
|
|
7
|
+
* POST /api/coupons/validate
|
|
8
|
+
*/
|
|
9
|
+
validate(ctx: any): Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Redeem coupon endpoint
|
|
12
|
+
* POST /api/coupons/redeem
|
|
13
|
+
*/
|
|
14
|
+
redeem(ctx: any): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Create coupon endpoint (Admin only)
|
|
17
|
+
* POST /api/coupons
|
|
18
|
+
*/
|
|
19
|
+
create(ctx: any): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Find all coupons
|
|
22
|
+
* GET /api/coupons
|
|
23
|
+
*/
|
|
24
|
+
find(ctx: any): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Find one coupon
|
|
27
|
+
* GET /api/coupons/:id
|
|
28
|
+
*/
|
|
29
|
+
findOne(ctx: any): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Update coupon
|
|
32
|
+
* PUT /api/coupons/:id
|
|
33
|
+
*/
|
|
34
|
+
update(ctx: any): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete coupon
|
|
37
|
+
* DELETE /api/coupons/:id
|
|
38
|
+
*/
|
|
39
|
+
delete(ctx: any): Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
export default _default;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ({ strapi }) => ({
|
|
4
|
+
/**
|
|
5
|
+
* Validate coupon endpoint
|
|
6
|
+
* POST /api/coupons/validate
|
|
7
|
+
*/
|
|
8
|
+
async validate(ctx) {
|
|
9
|
+
try {
|
|
10
|
+
const { couponCode, phoneNumber, orderAmount } = ctx.request.body;
|
|
11
|
+
// Validate required fields
|
|
12
|
+
if (!couponCode || !phoneNumber) {
|
|
13
|
+
return ctx.badRequest('Missing required fields: couponCode, phoneNumber');
|
|
14
|
+
}
|
|
15
|
+
const result = await strapi
|
|
16
|
+
.plugin('coupon')
|
|
17
|
+
.service('coupon')
|
|
18
|
+
.validate({
|
|
19
|
+
couponCode,
|
|
20
|
+
phoneNumber,
|
|
21
|
+
orderAmount,
|
|
22
|
+
});
|
|
23
|
+
ctx.body = result;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
strapi.log.error('Controller error in validate:', error);
|
|
27
|
+
ctx.internalServerError('An error occurred while validating the coupon');
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Redeem coupon endpoint
|
|
32
|
+
* POST /api/coupons/redeem
|
|
33
|
+
*/
|
|
34
|
+
async redeem(ctx) {
|
|
35
|
+
try {
|
|
36
|
+
const { couponCode, phoneNumber, orderId, orderAmount } = ctx.request.body;
|
|
37
|
+
// Validate required fields
|
|
38
|
+
if (!couponCode || !phoneNumber || !orderId) {
|
|
39
|
+
return ctx.badRequest('Missing required fields: couponCode, phoneNumber, orderId');
|
|
40
|
+
}
|
|
41
|
+
const result = await strapi
|
|
42
|
+
.plugin('coupon')
|
|
43
|
+
.service('coupon')
|
|
44
|
+
.redeem({
|
|
45
|
+
couponCode,
|
|
46
|
+
phoneNumber,
|
|
47
|
+
orderId,
|
|
48
|
+
orderAmount,
|
|
49
|
+
});
|
|
50
|
+
ctx.body = result;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
strapi.log.error('Controller error in redeem:', error);
|
|
54
|
+
ctx.internalServerError('An error occurred while redeeming the coupon');
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Create coupon endpoint (Admin only)
|
|
59
|
+
* POST /api/coupons
|
|
60
|
+
*/
|
|
61
|
+
async create(ctx) {
|
|
62
|
+
try {
|
|
63
|
+
const { code, discountType, discountValue, maxUsage, validFrom, validTo, description, userRestrictions, } = ctx.request.body;
|
|
64
|
+
// Validate required fields
|
|
65
|
+
if (!code || !discountType || !discountValue || !validFrom || !validTo) {
|
|
66
|
+
return ctx.badRequest('Missing required fields: code, discountType, discountValue, validFrom, validTo');
|
|
67
|
+
}
|
|
68
|
+
const result = await strapi
|
|
69
|
+
.plugin('coupon')
|
|
70
|
+
.service('coupon')
|
|
71
|
+
.create({
|
|
72
|
+
code,
|
|
73
|
+
discountType,
|
|
74
|
+
discountValue,
|
|
75
|
+
maxUsage,
|
|
76
|
+
validFrom,
|
|
77
|
+
validTo,
|
|
78
|
+
description,
|
|
79
|
+
userRestrictions,
|
|
80
|
+
});
|
|
81
|
+
if (!result.success) {
|
|
82
|
+
return ctx.badRequest(result.message, { errorCode: result.errorCode });
|
|
83
|
+
}
|
|
84
|
+
ctx.body = result;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
strapi.log.error('Controller error in create:', error);
|
|
88
|
+
ctx.internalServerError('An error occurred while creating the coupon');
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Find all coupons
|
|
93
|
+
* GET /api/coupons
|
|
94
|
+
*/
|
|
95
|
+
async find(ctx) {
|
|
96
|
+
try {
|
|
97
|
+
const coupons = await strapi.plugin('coupon').service('coupon').findAll(ctx.query);
|
|
98
|
+
ctx.body = coupons;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
strapi.log.error('Controller error in find:', error);
|
|
102
|
+
ctx.internalServerError('An error occurred while fetching coupons');
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Find one coupon
|
|
107
|
+
* GET /api/coupons/:id
|
|
108
|
+
*/
|
|
109
|
+
async findOne(ctx) {
|
|
110
|
+
try {
|
|
111
|
+
const { id } = ctx.params;
|
|
112
|
+
const coupon = await strapi.plugin('coupon').service('coupon').findOne(id);
|
|
113
|
+
if (!coupon) {
|
|
114
|
+
return ctx.notFound('Coupon not found');
|
|
115
|
+
}
|
|
116
|
+
ctx.body = coupon;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
strapi.log.error('Controller error in findOne:', error);
|
|
120
|
+
ctx.internalServerError('An error occurred while fetching the coupon');
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Update coupon
|
|
125
|
+
* PUT /api/coupons/:id
|
|
126
|
+
*/
|
|
127
|
+
async update(ctx) {
|
|
128
|
+
try {
|
|
129
|
+
const { id } = ctx.params;
|
|
130
|
+
const data = ctx.request.body;
|
|
131
|
+
const coupon = await strapi.plugin('coupon').service('coupon').update(id, data);
|
|
132
|
+
ctx.body = coupon;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
strapi.log.error('Controller error in update:', error);
|
|
136
|
+
ctx.internalServerError('An error occurred while updating the coupon');
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Delete coupon
|
|
141
|
+
* DELETE /api/coupons/:id
|
|
142
|
+
*/
|
|
143
|
+
async delete(ctx) {
|
|
144
|
+
try {
|
|
145
|
+
const { id } = ctx.params;
|
|
146
|
+
const coupon = await strapi.plugin('coupon').service('coupon').delete(id);
|
|
147
|
+
ctx.body = coupon;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
strapi.log.error('Controller error in delete:', error);
|
|
151
|
+
ctx.internalServerError('An error occurred while deleting the coupon');
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const coupon_1 = __importDefault(require("./coupon"));
|
|
7
|
+
exports.default = {
|
|
8
|
+
coupon: coupon_1.default,
|
|
9
|
+
};
|