forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
material.ts
35 lines (31 loc) · 1.23 KB
/
material.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Type } from 'class-transformer';
import { IsUUID, ValidateNested } from 'class-validator';
import { MapPosition, MapCoordinates } from '../../models/utils';
import { changePositionWithId } from '../../models/utils/position/position-helpers-mutable';
import { UUID, uuidValidationOptions } from '../../utils';
import { IsValue } from '../../utils/validators';
import type { Action, ActionReducer } from '../action-reducer';
export class MoveMaterialAction implements Action {
@IsValue('[Material] Move material' as const)
public readonly type = '[Material] Move material';
@IsUUID(4, uuidValidationOptions)
public readonly materialId!: UUID;
@ValidateNested()
@Type(() => MapCoordinates)
public readonly targetPosition!: MapCoordinates;
}
export namespace MaterialActionReducers {
export const moveMaterial: ActionReducer<MoveMaterialAction> = {
action: MoveMaterialAction,
reducer: (draftState, { materialId, targetPosition }) => {
changePositionWithId(
materialId,
MapPosition.create(targetPosition),
'material',
draftState
);
return draftState;
},
rights: 'participant',
};
}