mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Reorganize project. Add folder for shared code between backend/dashboard. Switch from jest to ava for tests.
This commit is contained in:
parent
80a82fe348
commit
16111bbe84
162 changed files with 11056 additions and 9900 deletions
38
backend/src/data/ApiUserInfo.ts
Normal file
38
backend/src/data/ApiUserInfo.ts
Normal 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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue