import { UnauthorizedError } from '../../errors/UnathorizedError.js';
export async function update(args) {
    const { key, req: { payload }, req, user, value } = args;
    if (!user) {
        throw new UnauthorizedError(req.t);
    }
    const collection = 'payload-preferences';
    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,
        data: preference,
        req,
        where
    });
}

//# sourceMappingURL=update.js.map