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
43 lines
1.0 KiB
Plaintext
43 lines
1.0 KiB
Plaintext
import { UnauthorizedError } from '../../errors/UnauthorizedError.js';
|
|
import { preferencesCollectionSlug } from '../config.js';
|
|
export async function update(args) {
|
|
const { key, req: { payload }, req, user, value } = args;
|
|
if (!user) {
|
|
throw new UnauthorizedError(req.t);
|
|
}
|
|
const where = {
|
|
and: [
|
|
{
|
|
key: {
|
|
equals: key
|
|
}
|
|
},
|
|
{
|
|
'user.value': {
|
|
equals: user.id
|
|
}
|
|
},
|
|
{
|
|
'user.relationTo': {
|
|
equals: user.collection
|
|
}
|
|
}
|
|
]
|
|
};
|
|
const preference = {
|
|
key,
|
|
user: {
|
|
relationTo: user.collection,
|
|
value: user.id
|
|
},
|
|
value
|
|
};
|
|
return await payload.db.upsert({
|
|
collection: preferencesCollectionSlug,
|
|
data: preference,
|
|
req,
|
|
where
|
|
});
|
|
}
|
|
|
|
//# sourceMappingURL=update.js.map |