Files
sharper.ly/apps/cms/src/bootstrap/reminder-settings.ts
T

40 lines
1.2 KiB
TypeScript

import type { Core } from '@strapi/strapi';
import { LOG_PREFIX } from './constants';
const REMINDER_SETTINGS_UID = 'api::reminder-settings.reminder-settings';
/**
* The values the reminder cron job falls back to when no `reminder-settings`
* single type exists yet (first boot on an empty database). The admin panel
* owns these values from then on; this is only the bootstrap default.
*/
export const DEFAULT_REMINDER_SETTINGS = {
enabled: true,
leadHours: 48,
} as const;
/**
* Create the `reminder-settings` single type if the database does not have one
* yet, so the values the reminder cron job depends on exist and are editable in
* the admin panel after the very first boot. Never overwrites an existing row.
*/
export const ensureReminderSettings = async (strapi: Core.Strapi): Promise<void> => {
const existing = await strapi
.documents(REMINDER_SETTINGS_UID)
.findFirst({});
if (existing) {
return;
}
await strapi.documents(REMINDER_SETTINGS_UID).create({
data: { ...DEFAULT_REMINDER_SETTINGS },
});
strapi.log.info(
`${LOG_PREFIX} created reminder-settings single type with defaults ` +
`(enabled=${DEFAULT_REMINDER_SETTINGS.enabled}, ` +
`leadHours=${DEFAULT_REMINDER_SETTINGS.leadHours}).`
);
};