fix(db-postgres): deleteOne fails when the where query does not resolve to any document (#11632)
Previously, if you called `payload.db.deleteOne` with a `where` query that does not resolve to anything, an error would be occurred.
This commit is contained in:
@@ -59,6 +59,10 @@ export const deleteOne: DeleteOne = async function deleteOne(
|
||||
docToDelete = await db.query[tableName].findFirst(findManyArgs)
|
||||
}
|
||||
|
||||
if (!docToDelete) {
|
||||
return null
|
||||
}
|
||||
|
||||
const result =
|
||||
returning === false
|
||||
? null
|
||||
|
||||
@@ -2134,6 +2134,16 @@ describe('database', () => {
|
||||
expect(query3.totalDocs).toEqual(1)
|
||||
})
|
||||
|
||||
it('db.deleteOne should not fail if query does not resolve to any document', async () => {
|
||||
await expect(
|
||||
payload.db.deleteOne({
|
||||
collection: 'posts',
|
||||
returning: false,
|
||||
where: { title: { equals: 'some random title' } },
|
||||
}),
|
||||
).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('mongodb additional keys stripping', async () => {
|
||||
// eslint-disable-next-line jest/no-conditional-in-test
|
||||
if (payload.db.name !== 'mongoose') {
|
||||
|
||||
Reference in New Issue
Block a user