|
@@ -1,13 +1,17 @@
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
import { Repository } from 'typeorm';
|
|
|
import { WorldEntity } from '../models/world.entity';
|
|
|
+import { FortuneEntity } from '../models/fortune.entity';
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
|
@Injectable()
|
|
|
export class BenchService {
|
|
|
constructor(
|
|
|
@InjectRepository(WorldEntity)
|
|
|
- private worldRepository: Repository<WorldEntity>){}
|
|
|
+ private worldRepository: Repository<WorldEntity>,
|
|
|
+ @InjectRepository(FortuneEntity)
|
|
|
+ private fortuneRepository: Repository<FortuneEntity>,
|
|
|
+ ){}
|
|
|
|
|
|
getOne(){
|
|
|
|
|
@@ -16,28 +20,33 @@ export class BenchService {
|
|
|
|
|
|
async getMultiple(totalQueries: string) {
|
|
|
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- const worldArr = [];
|
|
|
- const total = this.sanitizeQueries(totalQueries);
|
|
|
- for (let i = 0; i < total; i++) {
|
|
|
- worldArr.push(await this.getOne());
|
|
|
- }
|
|
|
- resolve(worldArr);
|
|
|
- });
|
|
|
+ const worldArr = [];
|
|
|
+ const total = this.sanitizeQueries(totalQueries);
|
|
|
+ for (let i = 0; i < total; i++) {
|
|
|
+ worldArr.push(await this.getOne());
|
|
|
+ }
|
|
|
+ return worldArr;
|
|
|
}
|
|
|
|
|
|
async updateMultiple(totalQueries: string) {
|
|
|
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- const worldArr = [];
|
|
|
- const total = this.sanitizeQueries(totalQueries);
|
|
|
- for (let i = 0; i < total; i++) {
|
|
|
- let worldToUpdate = await this.getOne();
|
|
|
- worldToUpdate.randomnumber = Math.floor(Math.random() * 10000) + 1;
|
|
|
- worldToUpdate = await this.worldRepository.save(worldToUpdate);
|
|
|
- worldArr.push(worldToUpdate);
|
|
|
- }
|
|
|
- resolve(worldArr);
|
|
|
+ const worldArr = [];
|
|
|
+ const total = this.sanitizeQueries(totalQueries);
|
|
|
+ for (let i = 0; i < total; i++) {
|
|
|
+ let worldToUpdate = await this.getOne();
|
|
|
+ worldToUpdate.randomnumber = Math.floor(Math.random() * 10000) + 1;
|
|
|
+ worldArr.push(worldToUpdate);
|
|
|
+ await this.worldRepository.update(worldToUpdate.id, worldToUpdate);
|
|
|
+ }
|
|
|
+ return worldArr;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getFortunes(){
|
|
|
+ return this.fortuneRepository.find().then((fortunes) => {
|
|
|
+ const newFortune = { id: 0, message: "Additional fortune added at request time." };
|
|
|
+ fortunes.push(newFortune);
|
|
|
+ fortunes.sort((a, b) => (a.message < b.message) ? -1 : 1);
|
|
|
+ return fortunes;
|
|
|
});
|
|
|
}
|
|
|
|