Файловый менеджер - Редактировать - /home/freeclou/app.optimyar.com/front-web/build/assets/resources/agGrid/discount.tar
Назад
config/routes.json 0000644 00000002532 15111633071 0010225 0 ustar 00 { "routes": [ { "method": "GET", "path": "/discounts", "handler": "discount.find", "config": { "policies": [] } }, { "method": "GET", "path": "/discounts/count", "handler": "discount.count", "config": { "policies": [] } }, { "method": "GET", "path": "/discounts/:id", "handler": "discount.findOne", "config": { "policies": [] } }, { "method": "GET", "path": "/discounts/discountByCode/:code", "handler": "discount.discountByCode", "config": { "policies": [] } }, { "method": "GET", "path": "/discounts/getCurrentForLevel/:levelId", "handler": "discount.getCurrentForLevel", "config": { "policies": [] } }, { "method": "POST", "path": "/discounts", "handler": "discount.create", "config": { "policies": [] } }, { "method": "PUT", "path": "/discounts/:id", "handler": "discount.update", "config": { "policies": [] } }, { "method": "DELETE", "path": "/discounts/:id", "handler": "discount.delete", "config": { "policies": [] } } ] } controllers/discount.js 0000644 00000003637 15111633071 0011307 0 ustar 00 'use strict'; const {parseMultipartData, sanitizeEntity} = require('strapi-utils'); /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) * to customize this controller */ module.exports = { async create(ctx) { let entity; if (ctx.is('multipart')) { //const { data, files } = parseMultipartData(ctx); //entity = await strapi.services.restaurant.create(data, { files }); } else { const isValid = strapi.services.discount.isValid(ctx.request.body); if (!isValid) { return ctx.badRequest(null, "errors.invalidFormData"); } entity = await strapi.services.discount.create(ctx.request.body); } return sanitizeEntity(entity, {model: strapi.models.discount}) }, async find(ctx) { let entities; const {query} = ctx; const {user} = ctx.state; if (query._q || !strapi.services.helpers.isAdmin(user)) { entities = await strapi.services["discount"].search(query); } else { const teacherLevels = await strapi.query("course-level").find({teacher: user.id}); entities = await strapi.services["discount"].find({course_levels_in: teacherLevels.map(x => x.id)}); } return ctx.send(entities); }, async getCurrentForLevel(ctx){ const {levelId} = ctx.params; const entities = await strapi.query("discount").find({ _limit: 1, _sort: 'createdAt:desc', isEnabled:true, course_levels_in:[levelId], toDate_gt:Date.now(), isFreePay:false, disposable:false, }); return ctx.send(entities); }, async discountByCode(ctx) { const {code} = ctx.params; const {result, entity} = await strapi.services.discount.verifyGetByCode(code); if (result === false) { return ctx.badRequest(null, entity); } return sanitizeEntity(entity, {model: strapi.models.discount}); } }; documentation/1.0.0/discount.json 0000644 00000052227 15111633071 0012602 0 ustar 00 { "paths": { "/discounts": { "get": { "deprecated": false, "description": "", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Discount" } } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [ { "name": "_limit", "in": "query", "required": false, "description": "Maximum number of results possible", "schema": { "type": "integer" }, "deprecated": false }, { "name": "_sort", "in": "query", "required": false, "description": "Sort according to a specific field.", "schema": { "type": "string" }, "deprecated": false }, { "name": "_start", "in": "query", "required": false, "description": "Skip a specific number of entries (especially useful for pagination)", "schema": { "type": "integer" }, "deprecated": false }, { "name": "=", "in": "query", "required": false, "description": "Get entries that matches exactly your input", "schema": { "type": "string" }, "deprecated": false }, { "name": "_ne", "in": "query", "required": false, "description": "Get records that are not equals to something", "schema": { "type": "string" }, "deprecated": false }, { "name": "_lt", "in": "query", "required": false, "description": "Get record that are lower than a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_lte", "in": "query", "required": false, "description": "Get records that are lower than or equal to a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_gt", "in": "query", "required": false, "description": "Get records that are greater than a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_gte", "in": "query", "required": false, "description": "Get records that are greater than or equal a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_contains", "in": "query", "required": false, "description": "Get records that contains a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_containss", "in": "query", "required": false, "description": "Get records that contains (case sensitive) a value", "schema": { "type": "string" }, "deprecated": false }, { "name": "_in", "in": "query", "required": false, "description": "Get records that matches any value in the array of values", "schema": { "type": "array", "items": { "type": "string" } }, "deprecated": false }, { "name": "_nin", "in": "query", "required": false, "description": "Get records that doesn't match any value in the array of values", "schema": { "type": "array", "items": { "type": "string" } }, "deprecated": false } ] }, "post": { "deprecated": false, "description": "Create a new record", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Discount" } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "requestBody": { "description": "", "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NewDiscount" } } } } } }, "/discounts/count": { "get": { "deprecated": false, "description": "", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "properties": { "count": { "type": "integer" } } } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [] } }, "/discounts/{id}": { "get": { "deprecated": false, "description": "", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Discount" } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [ { "name": "id", "in": "path", "description": "", "deprecated": false, "required": true, "schema": { "type": "string" } } ] }, "put": { "deprecated": false, "description": "Update a record", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Discount" } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "requestBody": { "description": "", "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NewDiscount" } } } }, "parameters": [ { "name": "id", "in": "path", "description": "", "deprecated": false, "required": true, "schema": { "type": "string" } } ] }, "delete": { "deprecated": false, "description": "Delete a record", "responses": { "200": { "description": "deletes a single record based on the ID supplied", "content": { "application/json": { "schema": { "type": "integer", "format": "int64" } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [ { "name": "id", "in": "path", "description": "", "deprecated": false, "required": true, "schema": { "type": "string" } } ] } }, "/discounts/discountByCode/{code}": { "get": { "deprecated": false, "description": "", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "properties": { "foo": { "type": "string" } } } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [ { "name": "code", "in": "path", "description": "", "deprecated": false, "required": true, "schema": { "type": "string" } } ] } }, "/discounts/getCurrentForLevel/{levelId}": { "get": { "deprecated": false, "description": "", "responses": { "200": { "description": "response", "content": { "application/json": { "schema": { "properties": { "foo": { "type": "string" } } } } } }, "403": { "description": "Forbidden", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "default": { "description": "unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }, "summary": "", "tags": [ "Discount" ], "parameters": [ { "name": "levelId", "in": "path", "description": "", "deprecated": false, "required": true, "schema": { "type": "string" } } ] } } }, "components": { "schemas": { "Discount": { "required": [ "id", "code", "amount", "fromDate", "toDate", "key" ], "properties": { "id": { "type": "string" }, "code": { "type": "string" }, "amount": { "type": "number" }, "fromDate": { "type": "string", "format": "date-time" }, "toDate": { "type": "string", "format": "date-time" }, "isEnabled": { "type": "boolean", "default": true }, "title": { "type": "string" }, "isAutoGenerated": { "type": "boolean" }, "minGroupCount": { "type": "integer", "default": 1 }, "isGroup": { "type": "boolean" }, "disposable": { "type": "boolean", "default": false }, "course_levels": { "type": "array", "items": { "required": [ "id", "title", "price", "fromDate", "toDate" ], "properties": { "id": { "type": "string" }, "title": { "type": "string" }, "coverImage": { "type": "string" }, "price": { "type": "integer" }, "desc": { "type": "string" }, "enableDiscount": { "type": "boolean" }, "sessions": { "type": "array", "items": { "type": "string" } }, "fromDate": { "type": "string" }, "toDate": { "type": "string" }, "status": { "type": "string", "enum": [ "register", "progress", "finish", "preRegister", "registerFinish" ] }, "location": { "type": "string" }, "infoLink": { "type": "string" }, "isLive": { "type": "boolean" }, "isGeneral": { "type": "boolean" }, "course": { "type": "string" }, "teacher": { "type": "string" }, "desc2": { "type": "string" }, "created_by": { "type": "string" }, "updated_by": { "type": "string" } } } }, "isFreePay": { "type": "boolean" }, "maxUseCount": { "type": "integer" } } }, "NewDiscount": { "required": [ "code", "amount", "fromDate", "toDate", "key" ], "properties": { "code": { "type": "string" }, "amount": { "type": "number" }, "fromDate": { "type": "string", "format": "date-time" }, "toDate": { "type": "string", "format": "date-time" }, "isEnabled": { "type": "boolean", "default": true }, "title": { "type": "string" }, "isAutoGenerated": { "type": "boolean" }, "key": { "type": "string" }, "minGroupCount": { "type": "integer", "default": 1 }, "isGroup": { "type": "boolean" }, "disposable": { "type": "boolean", "default": false }, "course_levels": { "type": "array", "items": { "type": "string" } }, "isFreePay": { "type": "boolean" }, "maxUseCount": { "type": "integer" }, "created_by": { "type": "string" }, "updated_by": { "type": "string" } } } } }, "tags": [ { "name": "Discount" } ] } models/discount.js 0000644 00000000256 15111633071 0010216 0 ustar 00 'use strict'; /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks) * to customize this model */ module.exports = {}; models/discount.settings.json 0000644 00000002343 15111633071 0012411 0 ustar 00 { "kind": "collectionType", "collectionName": "discounts", "info": { "name": "Discount", "description": "" }, "options": { "increments": true, "timestamps": true, "draftAndPublish": false }, "attributes": { "code": { "type": "string", "regex": "^\\w+$", "required": true }, "amount": { "type": "decimal", "max": 100, "min": 1, "required": true }, "fromDate": { "type": "datetime", "required": true }, "toDate": { "type": "datetime", "required": true }, "isEnabled": { "type": "boolean", "default": true }, "title": { "type": "string" }, "isAutoGenerated": { "type": "boolean" }, "key": { "type": "string", "required": true, "private": true }, "minGroupCount": { "type": "integer", "default": 1, "min": 1, "max": 20 }, "isGroup": { "type": "boolean" }, "disposable": { "type": "boolean", "default": false }, "course_levels": { "collection": "course-level" }, "isFreePay": { "type": "boolean" }, "maxUseCount": { "type": "integer" } } } services/discount.js 0000644 00000005325 15111633071 0010560 0 ustar 00 'use strict'; /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/services.html#core-services) * to customize this service */ module.exports = { getClientKey(data) { let {amount, code} = data; amount = amount / 65; return code.substr(0, 2) + amount.toString() + strapi.services.helpers.reverseString(code.substr(2)); }, async isValid(data) { const expectedKey = this.getClientKey(data); //other validations return expectedKey === data.key; }, async create(data, {files} = {}) { data.key = strapi.services.helpers.reverseString(data.key); const entry = await strapi.query('discount').create(data); // if (files) { // // automatically uploads the files based on the entry and the model // await strapi.entityService.uploadFiles(entry, files, { // model: 'restaurant', // // if you are using a plugin's model you will have to add the `plugin` key (plugin: 'users-permissions') // }); // return this.findOne({ id: entry.id }); // } return entry; }, async verifyGetByCode(code) { const letterNumber = /^[0-9a-zA-Z_]+$/; if (code && !code.match(letterNumber)) { return {result: false, entity: "buyCourse.errors.invalidDiscount"}; } //always verify result is a object : {result:boolean , message:any} const entity = await strapi.services.discount.findOne({code}); if (entity == null) { return {result: false, entity: "buyCourse.errors.invalidDiscount"}; } return this.verifyDiscountForUse(entity) }, async verifyDiscountForUse(entity) { if (entity == null || !entity.isEnabled) { return {result: false, entity: "buyCourse.errors.invalidDiscount"}; } if (!strapi.services.helpers.isNowBetweenDates(entity.fromDate, entity.toDate)) { return {result: false, entity: "buyCourse.errors.expiredDiscount"}; } return {result: true, entity}; }, async verifyGetByCodeAndCourse(code, levelId) { const byCode = await this.verifyGetByCode(code); if (byCode.result === true) { if (byCode.entity.course_levels && byCode.entity.course_levels.length) { if (byCode.entity.course_levels.findIndex(l => l.id === levelId) === -1) { return {result: false, entity: "errors.discountNotForCourse"}; } if (byCode.entity.maxUseCount) { const list = await strapi.services["user-course"].find( { course_levels: [levelId], discount: byCode.entity.id, isConfirm: true }); if (list && list.length >= byCode.entity.maxUseCount) { return {result: false, entity: "errors.discountMaxUseCount"}; } } } } return byCode; } };
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка