2018-02-02 00:06:01 +01:00
|
|
|
import * as mongo from 'mongodb';
|
2019-03-19 10:47:14 +01:00
|
|
|
import * as deepcopy from 'deepcopy';
|
2018-03-29 13:32:18 +02:00
|
|
|
import db from '../db/mongodb';
|
2017-01-17 01:12:33 +01:00
|
|
|
|
2018-02-02 00:06:01 +01:00
|
|
|
const Signin = db.get<ISignin>('signin');
|
|
|
|
export default Signin;
|
|
|
|
|
|
|
|
export interface ISignin {
|
|
|
|
_id: mongo.ObjectID;
|
2018-03-29 07:48:47 +02:00
|
|
|
createdAt: Date;
|
|
|
|
userId: mongo.ObjectID;
|
|
|
|
ip: string;
|
|
|
|
headers: any;
|
|
|
|
success: boolean;
|
2018-02-02 00:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pack a signin record for API response
|
|
|
|
*
|
|
|
|
* @param {any} record
|
|
|
|
* @return {Promise<any>}
|
|
|
|
*/
|
|
|
|
export const pack = (
|
|
|
|
record: any
|
|
|
|
) => new Promise<any>(async (resolve, reject) => {
|
|
|
|
|
|
|
|
const _record = deepcopy(record);
|
|
|
|
|
|
|
|
// Rename _id to id
|
|
|
|
_record.id = _record._id;
|
|
|
|
delete _record._id;
|
|
|
|
|
|
|
|
resolve(_record);
|
|
|
|
});
|