Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
96 lines
2.7 KiB
Plaintext
96 lines
2.7 KiB
Plaintext
import { deleteHandler } from './requestHandlers/delete.js';
|
|
import { findByIDHandler } from './requestHandlers/findOne.js';
|
|
import { updateHandler } from './requestHandlers/update.js';
|
|
const preferenceAccess = ({ req })=>{
|
|
if (!req.user) {
|
|
return false;
|
|
}
|
|
const userValueCondition = {
|
|
'user.value': {
|
|
equals: req.user.id
|
|
}
|
|
};
|
|
const userRelationCondition = {
|
|
'user.relationTo': {
|
|
equals: req.user.collection
|
|
}
|
|
};
|
|
return {
|
|
and: [
|
|
userValueCondition,
|
|
userRelationCondition
|
|
]
|
|
};
|
|
};
|
|
export const preferencesCollectionSlug = 'payload-preferences';
|
|
export const getPreferencesCollection = (config)=>({
|
|
slug: preferencesCollectionSlug,
|
|
access: {
|
|
delete: preferenceAccess,
|
|
read: preferenceAccess
|
|
},
|
|
admin: {
|
|
hidden: true
|
|
},
|
|
endpoints: [
|
|
{
|
|
handler: findByIDHandler,
|
|
method: 'get',
|
|
path: '/:key'
|
|
},
|
|
{
|
|
handler: deleteHandler,
|
|
method: 'delete',
|
|
path: '/:key'
|
|
},
|
|
{
|
|
handler: updateHandler,
|
|
method: 'post',
|
|
path: '/:key'
|
|
}
|
|
],
|
|
fields: [
|
|
{
|
|
name: 'user',
|
|
type: 'relationship',
|
|
hooks: {
|
|
beforeValidate: [
|
|
({ req })=>{
|
|
if (!req?.user) {
|
|
return null;
|
|
}
|
|
return {
|
|
relationTo: req?.user.collection,
|
|
value: req?.user.id
|
|
};
|
|
}
|
|
]
|
|
},
|
|
index: true,
|
|
relationTo: config.collections.filter((collectionConfig)=>collectionConfig.auth).map((collectionConfig)=>collectionConfig.slug),
|
|
required: true
|
|
},
|
|
{
|
|
name: 'key',
|
|
type: 'text',
|
|
index: true
|
|
},
|
|
{
|
|
name: 'value',
|
|
type: 'json',
|
|
validate: (value)=>{
|
|
if (value) {
|
|
try {
|
|
JSON.parse(JSON.stringify(value));
|
|
} catch {
|
|
return 'Invalid JSON';
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
],
|
|
lockDocuments: false
|
|
});
|
|
|
|
//# sourceMappingURL=config.js.map |