Files
klz-cables.com/.pnpm-store/v10/files/5a/0afe831c867ed7ace2fc60421447ea7fd9b9e396d5af260ad7a1a2837b96ff6c50e8e44954c57ed3a397c5bca9ece56facc4d5c226336647af3736539465db
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

72 lines
2.1 KiB
Plaintext

import { jobAfterRead, jobsCollectionSlug } from '../config/collection.js';
/**
* Convenience method for updateJobs by id
*/ export async function updateJob(args) {
const result = await updateJobs(args);
if (result) {
return result[0];
}
}
/**
* Helper for updating jobs in the most performant way possible.
* Handles deciding whether it can used direct db methods or not, and if so,
* manually runs the afterRead hook that populates the `taskStatus` property.
*/ export async function updateJobs({ id, data, depth, disableTransaction, limit: limitArg, req, returning, sort, where: whereArg }) {
const limit = id ? 1 : limitArg;
const where = id ? {
id: {
equals: id
}
} : whereArg;
if (depth || req.payload.config?.jobs?.runHooks) {
const result = await req.payload.update({
id,
collection: jobsCollectionSlug,
data,
depth,
disableTransaction,
limit,
req,
where
});
if (returning === false || !result) {
return null;
}
return result.docs;
}
const jobReq = {
transactionID: req.payload.db.name !== 'mongoose' ? await req.payload.db.beginTransaction() : undefined
};
if (typeof data.updatedAt === 'undefined') {
// Ensure updatedAt date is always updated
data.updatedAt = new Date().toISOString();
}
const args = id ? {
id,
data,
req: jobReq,
returning
} : {
data,
limit,
req: jobReq,
returning,
sort,
where: where
};
const updatedJobs = await req.payload.db.updateJobs(args);
if (req.payload.db.name !== 'mongoose' && jobReq.transactionID) {
await req.payload.db.commitTransaction(jobReq.transactionID);
}
if (returning === false || !updatedJobs?.length) {
return null;
}
return updatedJobs.map((updatedJob)=>{
return jobAfterRead({
config: req.payload.config,
doc: updatedJob
});
});
}
//# sourceMappingURL=updateJob.js.map