mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Co-authored-by: ian <licitdev@gmail.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
module.exports = function registerHooks({ action }, { services }) {
|
|
const logsCollection = 'tests_extensions_log';
|
|
|
|
action('test_items_no_relations_artists_integer.items.create', collectionsCallback);
|
|
action('test_items_no_relations_artists_string.items.create', collectionsCallback);
|
|
action('test_items_no_relations_artists_uuid.items.create', collectionsCallback);
|
|
|
|
async function collectionsCallback(data, { database, schema, accountability }) {
|
|
let key = `action-verify-create/${data.collection}`;
|
|
|
|
const itemService = new services.ItemsService(data.collection, { schema, accountability });
|
|
|
|
if (!data.payload.name) return;
|
|
|
|
if (data.payload.name.startsWith('one')) {
|
|
key += '/one';
|
|
} else if (data.payload.name.startsWith('many')) {
|
|
key += '/many';
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
key += `/${data.key}`;
|
|
|
|
try {
|
|
const item = await itemService.readOne(data.key);
|
|
|
|
if (item.name !== data.payload.name) {
|
|
throw 'Invalid item';
|
|
}
|
|
|
|
await database(logsCollection).insert({ key, value: '1' });
|
|
} catch (err) {
|
|
await database(logsCollection).insert({ key, value: '0' });
|
|
}
|
|
}
|
|
};
|