diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2019-09-02 04:41:26 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-02 04:41:26 +0900 |
| commit | 96b2267cb8ed9744f933e0682449b35922df527a (patch) | |
| tree | 2c1b957b02ef54e494965c537ea7ebe0b9291728 /src/services/chart/core.ts | |
| parent | Update README.md [AUTOGEN] (#5377) (diff) | |
| download | sharkey-96b2267cb8ed9744f933e0682449b35922df527a.tar.gz sharkey-96b2267cb8ed9744f933e0682449b35922df527a.tar.bz2 sharkey-96b2267cb8ed9744f933e0682449b35922df527a.zip | |
Chart resyncing (#5372)
* wip
* Add test
* Fix test
* Insert moderation log
* Add todo
Diffstat (limited to 'src/services/chart/core.ts')
| -rw-r--r-- | src/services/chart/core.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/services/chart/core.ts b/src/services/chart/core.ts index 60ba1ebb46..9dc250f753 100644 --- a/src/services/chart/core.ts +++ b/src/services/chart/core.ts @@ -65,7 +65,7 @@ export default abstract class Chart<T extends Record<string, any>> { public schema: Schema; protected repository: Repository<Log>; protected abstract genNewLog(latest: T): DeepPartial<T>; - protected abstract async fetchActual(group?: string): Promise<DeepPartial<T>>; + protected abstract async fetchActual(group: string | null): Promise<DeepPartial<T>>; @autobind private static convertSchemaToFlatColumnDefinitions(schema: Schema) { @@ -342,6 +342,24 @@ export default abstract class Chart<T extends Record<string, any>> { } @autobind + public async resync(group: string | null = null): Promise<any> { + const data = await this.fetchActual(group); + + const update = async (log: Log) => { + await this.repository.createQueryBuilder() + .update() + .set(Chart.convertObjectToFlattenColumns(data)) + .where('id = :id', { id: log.id }) + .execute(); + }; + + return Promise.all([ + this.getCurrentLog('day', group).then(log => update(log)), + this.getCurrentLog('hour', group).then(log => update(log)), + ]); + } + + @autobind protected async inc(inc: DeepPartial<T>, group: string | null = null): Promise<void> { await this.commit(Chart.convertQuery(inc as any), group); } |