UNPKG

@digicms/cms

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

32 lines (21 loc) 620 B
'use strict'; const transforms = require('./transforms'); const applyTransforms = (data, context) => { const { contentType } = context; const entries = Object.entries(data); for (const [attributeName, value] of entries) { const attribute = contentType.attributes[attributeName]; if (!attribute) { continue; } const transform = transforms[attribute.type]; if (transform) { const attributeContext = { ...context, attributeName, attribute }; data[attributeName] = transform(value, attributeContext); } } return data; }; module.exports = { applyTransforms, };