2019-02-15 07:25:55 +08:00
|
|
|
import {NextFunction, Request, Response} from 'express';
|
|
|
|
import {ErrorCodes, ErrorDTO} from '../../common/entities/Error';
|
2019-02-16 00:47:09 +08:00
|
|
|
import {ObjectManagers} from '../model/ObjectManagers';
|
2019-02-15 07:25:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
const LOG_TAG = '[PersonMWs]';
|
|
|
|
|
|
|
|
export class PersonMWs {
|
|
|
|
|
|
|
|
|
|
|
|
public static async listPersons(req: Request, res: Response, next: NextFunction) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2019-02-16 00:47:09 +08:00
|
|
|
req.resultPipe = await ObjectManagers.getInstance()
|
2019-02-15 07:25:55 +08:00
|
|
|
.PersonManager.getAll();
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error during listing the directory', err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static async getSamplePhoto(req: Request, res: Response, next: NextFunction) {
|
|
|
|
if (!req.params.name) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
const name = req.params.name;
|
|
|
|
try {
|
2019-02-16 00:47:09 +08:00
|
|
|
const photo = await ObjectManagers.getInstance()
|
2019-02-15 07:25:55 +08:00
|
|
|
.PersonManager.getSamplePhoto(name);
|
|
|
|
|
|
|
|
if (photo === null) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
req.resultPipe = photo;
|
|
|
|
return next();
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error during listing the directory', err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|