Skip to content

Commit 061b073

Browse files
authored
fix(softDelete): use _patch for softDelete (#9)
* fix(softDelete): use _patch for softDelete * fix: use addToQuery for softDelete
1 parent 8fd9c0e commit 061b073

File tree

16 files changed

+325
-202
lines changed

16 files changed

+325
-202
lines changed

src/hooks/cache/cache.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const cache = <H extends HookContext = HookContext>(
4747
await cacheBefore(context, cacheMap)
4848
await next()
4949
await cacheAfter(context, cacheMap)
50-
return context
50+
return
5151
}
5252
}
5353
}

src/hooks/check-required/check-required.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export function checkRequired<H extends HookContext = HookContext>(
4444
}
4545
}
4646

47-
if (next) return next().then(() => context)
47+
if (next) return next()
4848
}
4949
}

src/hooks/create-related/create-related.hook.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,5 @@ export function createRelated<
5353
}
5454
}),
5555
)
56-
57-
return context
5856
}
5957
}
Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
import { assert } from 'vitest'
22
import { disablePagination } from './disable-pagination.hook.js'
3+
import type { HookContext } from '@feathersjs/feathers'
34

4-
let hookBefore: any
5-
6-
describe('services disablePagination', () => {
7-
beforeEach(() => {
8-
hookBefore = {
5+
describe('hook - disablePagination', () => {
6+
it('disables on $limit = -1', () => {
7+
const result: any = disablePagination()({
98
type: 'before',
109
method: 'find',
1110
params: { query: { id: 1, $limit: -1 } },
12-
}
11+
} as HookContext)
12+
assert.deepEqual(result.params, { paginate: false, query: { id: 1 } })
1313
})
1414

15-
it('disables on $limit = -1', () => {
16-
hookBefore.params.query.$limit = -1
17-
18-
const result: any = disablePagination()(hookBefore)
15+
it('disables on $limit = "-1"', () => {
16+
const result: any = disablePagination()({
17+
type: 'before',
18+
method: 'find',
19+
params: { query: { id: 1, $limit: '-1' } },
20+
} as HookContext)
1921
assert.deepEqual(result.params, { paginate: false, query: { id: 1 } })
2022
})
2123

22-
it('disables on $limit = "-1"', () => {
23-
hookBefore.params.query.$limit = '-1'
24+
it('disables on $limit = -1 in around', () => {
25+
const result: any = disablePagination()({
26+
type: 'around',
27+
method: 'find',
28+
params: { query: { id: 1, $limit: -1 } },
29+
} as HookContext)
30+
assert.deepEqual(result.params, { paginate: false, query: { id: 1 } })
31+
})
2432

25-
const result: any = disablePagination()(hookBefore)
33+
it('disables on $limit = "-1" in around', () => {
34+
const result: any = disablePagination()({
35+
type: 'around',
36+
method: 'find',
37+
params: { query: { id: 1, $limit: '-1' } },
38+
} as HookContext)
2639
assert.deepEqual(result.params, { paginate: false, query: { id: 1 } })
2740
})
2841

2942
it('throws if after hook', () => {
30-
hookBefore.type = 'after'
31-
3243
assert.throws(() => {
33-
disablePagination()(hookBefore)
44+
disablePagination()({
45+
type: 'after',
46+
method: 'find',
47+
params: { query: { id: 1, $limit: -1 } },
48+
} as HookContext)
3449
})
3550
})
3651

3752
it('throws if not find', () => {
38-
hookBefore.method = 'get'
39-
4053
assert.throws(() => {
41-
disablePagination()(hookBefore)
54+
disablePagination()({
55+
type: 'before',
56+
method: 'get',
57+
params: { query: { id: 1, $limit: -1 } },
58+
} as HookContext)
4259
})
4360
})
4461
})

src/hooks/disable-pagination/disable-pagination.hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { checkContext } from '../../utils/index.js'
99
export const disablePagination =
1010
<H extends HookContext = HookContext>() =>
1111
(context: H, next?: NextFunction) => {
12-
checkContext(context, 'before', ['find'], 'disablePagination')
12+
checkContext(context, ['before', 'around'], ['find'], 'disablePagination')
1313
const $limit = context.params?.query?.$limit
1414

1515
if ($limit === '-1' || $limit === -1) {
1616
context.params.paginate = false
1717
delete context.params.query.$limit
1818
}
1919

20-
if (next) return next().then(() => context)
20+
if (next) return next()
2121

2222
return context
2323
}

src/hooks/disallow/disallow.hook.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert } from 'vitest'
22
import { disallow } from './disallow.hook.js'
33

4-
describe('services disallow', () => {
4+
describe('hook - disallow', () => {
55
describe('disallow is compatible with .disable (without predicate)', () => {
66
let hookRest: any
77
let hookSocketio: any

src/hooks/on-delete/on-delete.hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const onDelete = <
5858
const { result } = getResultIsArray(context)
5959

6060
if (!result.length) {
61-
return context
61+
return
6262
}
6363

6464
const promises: Promise<any>[] = []
@@ -102,6 +102,6 @@ export const onDelete = <
102102
await Promise.all(promises)
103103
}
104104

105-
return context
105+
return
106106
}
107107
}

0 commit comments

Comments
 (0)