Skip to content

Commit c1bed8b

Browse files
committed
contexts: add a default getByCode route
1 parent 3b99087 commit c1bed8b

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

contexts/TestCycle.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UnitSet } from './UnitSet'
66
import { getFieldName } from '../utils/getFieldName'
77
import { createGetAllRoute } from '../decorators/routes/getAll'
88
import { createGetByIdRoute } from '../decorators/routes/createGetByIdRoute'
9+
import { createGetByCodeRoute } from '../decorators/routes/createGetByCodeRoute'
910

1011
/**
1112
* A Test-Cycle represents the bridge between
@@ -164,3 +165,7 @@ TestCycle.routes.all = createGetAllRoute({
164165
TestCycle.routes.byId = createGetByIdRoute({
165166
context: TestCycle
166167
})
168+
169+
TestCycle.routes.byCode = createGetByCodeRoute({
170+
context: TestCycle
171+
})

contexts/Unit.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getFieldName } from '../utils/getFieldName'
55
import { createPageEntrySchema, createPageSchema } from '../validation/pageSchema'
66
import { createGetAllRoute } from '../decorators/routes/getAll'
77
import { createGetByIdRoute } from '../decorators/routes/createGetByIdRoute'
8+
import { createGetByCodeRoute } from '../decorators/routes/createGetByCodeRoute'
89

910
export const Unit = {}
1011

@@ -126,3 +127,7 @@ Unit.routes.all = createGetAllRoute({
126127
Unit.routes.byId = createGetByIdRoute({
127128
context: Unit
128129
})
130+
131+
Unit.routes.byCode = createGetByCodeRoute({
132+
context: Unit
133+
})

contexts/UnitSet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createPageEntrySchema, createPageSchema } from '../validation/pageSchem
88
import { trapCircular } from '../utils/trapCircular'
99
import { createGetAllRoute } from '../decorators/routes/getAll'
1010
import { createGetByIdRoute } from '../decorators/routes/createGetByIdRoute'
11+
import { createGetByCodeRoute } from '../decorators/routes/createGetByCodeRoute'
1112

1213
export const UnitSet = {}
1314

@@ -193,3 +194,7 @@ UnitSet.routes.all = createGetAllRoute({
193194
UnitSet.routes.byId = createGetByIdRoute({
194195
context: UnitSet
195196
})
197+
198+
UnitSet.routes.byCode = createGetByCodeRoute({
199+
context: UnitSet
200+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { check, Match } from 'meteor/check'
2+
import { onServer } from '../../utils/arch'
3+
4+
export const createGetByCodeRoute = ({ context, schema, run }) => {
5+
check(context?.name, String)
6+
check(schema, Match.Maybe(Object))
7+
check(run, Match.Maybe(Function))
8+
9+
return {
10+
path: `/api/${context.name}/get/byCode`,
11+
method: 'get',
12+
schema: schema || { shortCode: String },
13+
run: onServer(run)
14+
}
15+
}

0 commit comments

Comments
 (0)