Fix chart bug
This commit is contained in:
		| @@ -42,4 +42,17 @@ export default class TestChart extends Chart<TestLog> { | |||||||
| 			foo: update | 			foo: update | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	@autobind | ||||||
|  | 	public async decrement() { | ||||||
|  | 		const update: Obj = {}; | ||||||
|  |  | ||||||
|  | 		update.total = -1; | ||||||
|  | 		update.dec = 1; | ||||||
|  | 		this.total--; | ||||||
|  |  | ||||||
|  | 		await this.inc({ | ||||||
|  | 			foo: update | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -122,7 +122,7 @@ export default abstract class Chart<T extends Record<string, any>> { | |||||||
|  |  | ||||||
| 		for (const [k, v] of Object.entries(columns)) { | 		for (const [k, v] of Object.entries(columns)) { | ||||||
| 			if (v > 0) query[k] = () => `"${k}" + ${v}`; | 			if (v > 0) query[k] = () => `"${k}" + ${v}`; | ||||||
| 			if (v < 0) query[k] = () => `"${k}" - ${v}`; | 			if (v < 0) query[k] = () => `"${k}" - ${Math.abs(v)}`; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return query; | 		return query; | ||||||
|   | |||||||
| @@ -106,6 +106,30 @@ describe('Chart', () => { | |||||||
| 		}); | 		}); | ||||||
| 	})); | 	})); | ||||||
|  |  | ||||||
|  | 	 | ||||||
|  | 	it('Can updates (dec)', async(async () => { | ||||||
|  | 		await testChart.decrement(); | ||||||
|  |  | ||||||
|  | 		const chartHours = await testChart.getChart('hour', 3); | ||||||
|  | 		const chartDays = await testChart.getChart('day', 3); | ||||||
|  |  | ||||||
|  | 		assert.deepStrictEqual(chartHours, { | ||||||
|  | 			foo: { | ||||||
|  | 				dec: [1, 0, 0], | ||||||
|  | 				inc: [0, 0, 0], | ||||||
|  | 				total: [-1, 0, 0] | ||||||
|  | 			}, | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		assert.deepStrictEqual(chartDays, { | ||||||
|  | 			foo: { | ||||||
|  | 				dec: [1, 0, 0], | ||||||
|  | 				inc: [0, 0, 0], | ||||||
|  | 				total: [-1, 0, 0] | ||||||
|  | 			}, | ||||||
|  | 		}); | ||||||
|  | 	})); | ||||||
|  |  | ||||||
| 	it('Empty chart', async(async () => { | 	it('Empty chart', async(async () => { | ||||||
| 		const chartHours = await testChart.getChart('hour', 3); | 		const chartHours = await testChart.getChart('hour', 3); | ||||||
| 		const chartDays = await testChart.getChart('day', 3); | 		const chartDays = await testChart.getChart('day', 3); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo