0.12.17 : change ad feature
This commit is contained in:
@@ -42,11 +42,6 @@
|
||||
"applies": {
|
||||
"type": "integer"
|
||||
},
|
||||
"location": {
|
||||
"type": "component",
|
||||
"repeatable": false,
|
||||
"component": "address.full-address"
|
||||
},
|
||||
"contactname": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -58,6 +53,19 @@
|
||||
},
|
||||
"featured": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"location": {
|
||||
"type": "text"
|
||||
},
|
||||
"medias": {
|
||||
"allowedTypes": [
|
||||
"images",
|
||||
"files",
|
||||
"videos",
|
||||
"audios"
|
||||
],
|
||||
"type": "media",
|
||||
"multiple": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,47 @@
|
||||
* ad controller
|
||||
*/
|
||||
|
||||
import { factories } from '@strapi/strapi'
|
||||
import { factories } from "@strapi/strapi";
|
||||
|
||||
export default factories.createCoreController('api::ad.ad');
|
||||
export default factories.createCoreController("api::ad.ad", ({ strapi }) => ({
|
||||
async create(ctx) {
|
||||
// 1) Prépare le payload + upload banner
|
||||
const body = ctx.request.body as any;
|
||||
const data =
|
||||
typeof body?.data === "string" ? JSON.parse(body.data) : body?.data || {};
|
||||
data.author = ctx.state.user.id;
|
||||
data.medias = [];
|
||||
|
||||
const bannerInput = (ctx.request.files as any)?.medias;
|
||||
if (bannerInput) {
|
||||
const files = Array.isArray(bannerInput) ? bannerInput : [bannerInput];
|
||||
|
||||
for (const file of files) {
|
||||
const uploaded = await strapi
|
||||
.plugin("upload")
|
||||
.service("upload")
|
||||
.upload({
|
||||
data: {
|
||||
fileInfo: {
|
||||
alternativeText: data?.name || "media",
|
||||
caption: "media",
|
||||
name: file.originalFilename || "media",
|
||||
},
|
||||
},
|
||||
files: file,
|
||||
});
|
||||
|
||||
if (uploaded?.[0]?.id) {
|
||||
data.medias.push(uploaded[0].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//delete data.medias;
|
||||
|
||||
// 2) Crée le group via core controller
|
||||
ctx.request.body = { data };
|
||||
const response = await super.create(ctx); // { data: { id, attributes }, meta: {} }
|
||||
return response;
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user