handler method
- @override
override
Must be implemented
Implementation
@override
FutureOr<Response> handler() => checkApiSecret(request).fold(
(errorResponse) => errorResponse,
(_) async {
final action = HasuraAction.fromJson(
jsonDecode(await request.readAsString()),
);
final userRaw = action.input['user'];
final user = User.fromJson(userRaw);
final departmentsIds = user.departmentIds;
try {
final createdUser = await userRepository.createUser(user);
if (departmentsIds != null && departmentsIds.isNotEmpty) {
final duList = <DepartmentUser>[];
for (final dId in departmentsIds) {
if (dId == user.departmentId) continue;
duList.add(
DepartmentUser(
departmentId: dId,
userId: createdUser['userId'] as String,
splitBetweenDepartments: true,
),
);
}
await userRepository.createDepartmentUsers(duList);
}
return Response.ok(jsonEncode({'userKey': createdUser['userKey']}));
} catch (e) {
print('UserCreateController error: $e');
return Response.badRequest(
body: jsonEncode({'message': 'UserCreateController: $e'}),
);
}
},
);