Skip to content

Commit c1b3312

Browse files
committed
fix: findOne supports both numeric id and documentId
- findOne now accepts both numeric id (backward compat) and documentId - Fix syntax error in renderTemplate controller (split ctx.params) - Remove emoji from log messages - Support old URLs like /designer/templates/117
1 parent 6d19cec commit c1b3312

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

server/src/controllers/email-designer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ module.exports = ({ strapi }) => ({
208208
*/
209209
async renderTemplate(ctx) {
210210
try {
211-
const { templateReferenceId } = ct
212-
x.params;
211+
const { templateReferenceId } = ctx.params;
213212
const { data } = ctx.request.body;
214213

215214
const rendered = await strapi

server/src/services/email-designer.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,22 @@ module.exports = ({ strapi }) => ({
8080
},
8181

8282
/**
83-
* Get template by ID (documentId) with populated versions
83+
* Get template by ID (documentId or numeric id) with populated versions
84+
* Supports both documentId (string) and numeric id for backward compatibility
8485
*/
85-
async findOne(documentId) {
86+
async findOne(idOrDocumentId) {
87+
// Check if it's a numeric ID (backward compatibility)
88+
const isNumericId = /^\d+$/.test(String(idOrDocumentId));
89+
90+
if (isNumericId) {
91+
// Try to find by numeric id first
92+
const result = await this.findById(Number(idOrDocumentId));
93+
if (result) return result;
94+
}
95+
96+
// Try as documentId (Strapi v5 standard)
8697
return strapi.documents(EMAIL_TEMPLATE_UID).findOne({
87-
documentId,
98+
documentId: String(idOrDocumentId),
8899
populate: ['versions'],
89100
});
90101
},
@@ -354,7 +365,7 @@ module.exports = ({ strapi }) => ({
354365
* Get all versions for a template
355366
*/
356367
async getVersions(templateDocumentId) {
357-
strapi.log.info(`[magic-mail] 📜 Fetching versions for template documentId: ${templateDocumentId}`);
368+
strapi.log.info(`[magic-mail] [VERSION] Fetching versions for template documentId: ${templateDocumentId}`);
358369

359370
const template = await strapi.documents(EMAIL_TEMPLATE_UID).findOne({
360371
documentId: templateDocumentId,

0 commit comments

Comments
 (0)