21 lines
861 B
TypeScript
21 lines
861 B
TypeScript
import { nextHandler } from '../../../../../src/utils/errors'
|
|
import { validate } from '../../../../../src/validation'
|
|
import { GroupIdParam, GroupSetFactoryArrayBody } from '../../../../../src/types/ApiSchemas'
|
|
import { setFactoriesOfGroup } from '../../../../../src/database/groups'
|
|
import { waitForInitSchemas } from '../../../../../src/validation/schemas'
|
|
|
|
const handler = nextHandler(async (req, res) => {
|
|
if (req.method !== 'POST') throw new Error('Invalid method')
|
|
await waitForInitSchemas.resolve()
|
|
const { transformed: params } = validate<GroupIdParam>(req.query, '/GroupIdParam')
|
|
const { transformed: body } = validate<GroupSetFactoryArrayBody>(
|
|
req.body,
|
|
'/GroupSetFactoryArrayBody'
|
|
)
|
|
|
|
const success = await setFactoriesOfGroup(params.id, params.name, body.type, body.factories)
|
|
res.json({ success })
|
|
})
|
|
|
|
export default handler
|