Dashboard work and related

This commit is contained in:
Dragory 2019-06-23 19:18:41 +03:00
parent 7bda2b1763
commit b230a73a6f
44 changed files with 637 additions and 272 deletions

38
src/data/ApiUserInfo.ts Normal file
View file

@ -0,0 +1,38 @@
import { getRepository, Repository } from "typeorm";
import { ApiUserInfo as ApiUserInfoEntity, ApiUserInfoData } from "./entities/ApiUserInfo";
import { BaseRepository } from "./BaseRepository";
import { connection } from "./db";
import moment from "moment-timezone";
import { DBDateFormat } from "../utils";
export class ApiUserInfo extends BaseRepository {
private apiUserInfo: Repository<ApiUserInfoEntity>;
constructor() {
super();
this.apiUserInfo = getRepository(ApiUserInfoEntity);
}
get(id) {
return this.apiUserInfo.findOne({
where: {
id,
},
});
}
update(id, data: ApiUserInfoData) {
return connection.transaction(async entityManager => {
const repo = entityManager.getRepository(ApiUserInfoEntity);
const existingInfo = await repo.findOne({ where: { id } });
const updatedAt = moment().format(DBDateFormat);
if (existingInfo) {
await repo.update({ id }, { data, updated_at: updatedAt });
} else {
await repo.insert({ id, data, updated_at: updatedAt });
}
});
}
}