-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Lan2u/training_register_form
Register training sheet for equipment
- Loading branch information
Showing
18 changed files
with
340 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/node_modules/ | ||
/build/ | ||
/.cache/ | ||
.env | ||
*.ignore | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import {add} from './add'; | ||
import {addForm} from './add-form'; | ||
import {registerTrainingSheet} from './register-training-sheet'; | ||
|
||
export const equipment = { | ||
add: { | ||
...add, | ||
...addForm, | ||
}, | ||
training_sheet: { | ||
...registerTrainingSheet, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {DomainEvent, constructEvent} from '../../types'; | ||
import * as RA from 'fp-ts/ReadonlyArray'; | ||
import * as t from 'io-ts'; | ||
import * as tt from 'io-ts-types'; | ||
import * as O from 'fp-ts/Option'; | ||
import {pipe} from 'fp-ts/lib/function'; | ||
import {Command} from '../command'; | ||
import {isAdminOrSuperUser} from '../is-admin-or-super-user'; | ||
|
||
const codec = t.strict({ | ||
equipmentId: tt.UUID, | ||
trainingSheetId: t.string, | ||
}); | ||
|
||
type RegisterTrainingSheet = t.TypeOf<typeof codec>; | ||
|
||
const process = (input: { | ||
command: RegisterTrainingSheet; | ||
events: ReadonlyArray<DomainEvent>; | ||
}): O.Option<DomainEvent> => | ||
pipe( | ||
input.events, | ||
RA.match( | ||
() => | ||
O.some( | ||
constructEvent('EquipmentTrainingSheetRegistered')(input.command) | ||
), | ||
() => O.none | ||
) | ||
); | ||
|
||
const resource = (command: RegisterTrainingSheet) => ({ | ||
type: 'Equipment', | ||
id: command.equipmentId, | ||
}); | ||
|
||
export const registerTrainingSheet: Command<RegisterTrainingSheet> = { | ||
process, | ||
resource, | ||
decode: codec.decode, | ||
isAuthorized: isAdminOrSuperUser, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {pipe} from 'fp-ts/lib/function'; | ||
import * as RA from 'fp-ts/ReadonlyArray'; | ||
import * as O from 'fp-ts/Option'; | ||
import {DomainEvent, isEventOfType} from '../../types'; | ||
|
||
export const getTrainingSheetId = | ||
(events: ReadonlyArray<DomainEvent>) => | ||
(equipmentId: string): O.Option<string> => | ||
pipe( | ||
events, | ||
RA.filter(isEventOfType('EquipmentTrainingSheetRegistered')), | ||
RA.filter(event => event.equipmentId === equipmentId), | ||
RA.last, | ||
O.match( | ||
() => O.none, | ||
mostRecentSheet => O.some(mostRecentSheet.trainingSheetId) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {get} from './get'; | ||
import {getAll} from './get-all'; | ||
import {getForArea} from './get-for-area'; | ||
import {getTrainingSheetId} from './get-training-sheet-id'; | ||
|
||
export const equipment = { | ||
get, | ||
getAll, | ||
getForArea, | ||
getTrainingSheetId, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import express, {Router} from 'express'; | ||
import path from 'path'; | ||
import {oopsPage} from './templates'; | ||
import {Dependencies} from './dependencies'; | ||
import {configureAuthRoutes} from './authentication'; | ||
import {Config} from './configuration'; | ||
import {StatusCodes} from 'http-status-codes'; | ||
import {commands} from './commands'; | ||
import {queries} from './queries'; | ||
import {http} from './http'; | ||
|
||
export const createRouter = (deps: Dependencies, conf: Config): Router => { | ||
const router = Router(); | ||
|
||
router.get('/', queries.landing(deps)); | ||
|
||
router.get('/areas', queries.areas(deps)); | ||
router.get('/areas/create', http.formGet(deps, commands.area.create)); | ||
router.post( | ||
'/areas/create', | ||
http.formPost(deps, commands.area.create, '/areas') | ||
); | ||
router.get('/areas/add-owner', http.formGet(deps, commands.area.addOwner)); | ||
router.post( | ||
'/areas/add-owner', | ||
http.formPost(deps, commands.area.addOwner, '/areas') | ||
); | ||
router.get('/areas/:area', queries.area(deps)); | ||
router.post( | ||
'/api/create-area', | ||
http.apiPost(deps, conf, commands.area.create) | ||
); | ||
|
||
router.get( | ||
'/areas/:area/add-equipment', | ||
http.formGet(deps, commands.equipment.add) | ||
); | ||
router.get('/equipment', queries.allEquipment(deps)); | ||
router.post( | ||
'/equipment/add', | ||
http.formPost(deps, commands.equipment.add, '/equipment') | ||
); | ||
router.post( | ||
'/equipment/add-training-sheet', | ||
http.apiPost(deps, conf, commands.equipment.training_sheet) | ||
); | ||
|
||
router.get('/super-users', queries.superUsers(deps)); | ||
router.get( | ||
'/super-users/declare', | ||
http.formGet(deps, commands.superUser.declare) | ||
); | ||
router.post( | ||
'/super-users/declare', | ||
http.formPost(deps, commands.superUser.declare, '/super-users') | ||
); | ||
router.post( | ||
'/api/declare-super-user', | ||
http.apiPost(deps, conf, commands.superUser.declare) | ||
); | ||
router.get( | ||
'/super-users/revoke', | ||
http.formGet(deps, commands.superUser.revoke) | ||
); | ||
router.post( | ||
'/super-users/revoke', | ||
http.formPost(deps, commands.superUser.revoke, '/super-users') | ||
); | ||
router.post( | ||
'/api/revoke-super-user', | ||
http.apiPost(deps, conf, commands.superUser.revoke) | ||
); | ||
|
||
router.post( | ||
'/api/link-number-to-email', | ||
http.apiPost(deps, conf, commands.memberNumbers.linkNumberToEmail) | ||
); | ||
|
||
configureAuthRoutes(router); | ||
|
||
router.get('/ping', (req, res) => res.status(StatusCodes.OK).send('pong\n')); | ||
|
||
router.use('/static', express.static(path.resolve(__dirname, './static'))); | ||
|
||
router.use((req, res) => { | ||
res | ||
.status(StatusCodes.NOT_FOUND) | ||
.send(oopsPage('The page you have requested does not exist.')); | ||
}); | ||
return router; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.