0.12.17 : change ad feature

This commit is contained in:
2026-01-15 09:38:47 +01:00
parent 34a4f594ce
commit 1186463e11
6 changed files with 391 additions and 56 deletions
+13 -5
View File
@@ -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
}
}
}
+43 -2
View File
@@ -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;
},
}));