chore: accounts for globals in filter query
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { FilterQuery } from 'mongoose';
|
||||
import { Payload } from '../payload';
|
||||
import { CollectionModel } from '../collections/config/types';
|
||||
|
||||
@@ -26,18 +27,19 @@ export const enforceMaxVersions = async ({
|
||||
const oldestAllowedDoc = await Model.find(query).limit(1).skip(max).sort({ updatedAt: -1 });
|
||||
|
||||
if (oldestAllowedDoc?.[0]?.updatedAt) {
|
||||
await Model.deleteMany({
|
||||
const deleteQuery: FilterQuery<unknown> = {
|
||||
$and: [
|
||||
{
|
||||
parent: id,
|
||||
},
|
||||
{
|
||||
updatedAt: {
|
||||
$lte: oldestAllowedDoc[0].updatedAt,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
if (id) deleteQuery.$and.push({ parent: id });
|
||||
|
||||
await Model.deleteMany(deleteQuery);
|
||||
}
|
||||
} catch (err) {
|
||||
payload.logger.error(`There was an error cleaning up old versions for the ${entityType} ${slug}`);
|
||||
|
||||
Reference in New Issue
Block a user