bdd410672d
Change-Id: Iaa70ed769c7d693ff5172f4fd3204677e4834a8a
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
const {v4: uuidv4} = require("uuid");
|
|
module.exports = {
|
|
extend: '@apostrophecms/piece-type',
|
|
options: {
|
|
label: 'Platform',
|
|
},
|
|
|
|
fields: {
|
|
add: {
|
|
uuid: {
|
|
type: 'string',
|
|
label: 'UUID',
|
|
required: false
|
|
}
|
|
},
|
|
group: {
|
|
basics: {
|
|
label: 'Basics',
|
|
fields: ['uuid']
|
|
}
|
|
}
|
|
},
|
|
handlers(self) {
|
|
return {
|
|
beforeSave: {
|
|
async generateUuid(req, doc) {
|
|
if (!doc.uuid) {
|
|
doc.uuid = uuidv4();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
apiRoutes(self) {
|
|
return {
|
|
get: {
|
|
async all(req) {
|
|
const projection = {
|
|
title: 1,
|
|
uuid: 1,
|
|
};
|
|
try {
|
|
const platforms = await self.find(req).project(projection).toArray();
|
|
return platforms;
|
|
} catch (error) {
|
|
throw self.apos.error('notfound', 'Platforms not found');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}; |