'use strict' import { saveDomainToStorage, getDomainsFromStorage } from './storageService' import { WrongInputError, NotFoundError, InternalError } from '../../utils/customErrors' import { Request } from 'express' import { Domain } from './types' /** * Operations on /users/domain */ export default { /**Stores new domain */ async postUser(req: Request) { if (req && req.body && req.body.domain) { const domain: Domain = req.body.domain if (domain.domain && domain.role) { try { return await saveDomainToStorage(domain) } catch (error) { throw new InternalError(error) } } else { throw new WrongInputError('Elements domain and/or role are missing in domain') } } else { throw new WrongInputError('Invalid domain body.') } }, /**gets all domains */ async getDomains(req: Request) { try { return await getDomainsFromStorage() } catch (error) { throw new InternalError(error) } } }