Прогнал линтером для автоматических доделок, но оставлять его не стал - слишком много ошибок
This commit is contained in:
1 parent
ce3a192cbd
commit
c6db8bc2fe
14 files changed
+118
-8324
No files matched your search
+19
-15
@@ -8,8 +8,8 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
protected _storage: Storage
|
||||
protected _entity: T
|
||||
|
||||
protected _limit: number = 0
|
||||
protected _offset: number = 0
|
||||
protected _limit = 0
|
||||
protected _offset = 0
|
||||
|
||||
/**
|
||||
* Возвращает объект соотв. сущности, например new App()
|
||||
@@ -21,8 +21,7 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
*/
|
||||
abstract Name(): string
|
||||
|
||||
// @ts-ignore
|
||||
_transformer: (obj: any) => any
|
||||
_transformer: (object: any) => any
|
||||
|
||||
constructor(storage: Storage) {
|
||||
this._storage = storage
|
||||
@@ -31,10 +30,10 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
}
|
||||
|
||||
resetTransformer() {
|
||||
this._transformer = function (obj: any): any {
|
||||
this._transformer = function (object: any): any {
|
||||
const entity = this.Entity()
|
||||
entity.data.fromObject(obj)
|
||||
entity._id = obj._id
|
||||
entity.data.fromObject(object)
|
||||
entity._id = object._id
|
||||
return entity
|
||||
}
|
||||
}
|
||||
@@ -58,7 +57,8 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
`found few (${entryList.length}) entries in ${this.Name()} for id ${id}`
|
||||
)
|
||||
}
|
||||
if (entryList.length == 0) {
|
||||
|
||||
if (entryList.length === 0) {
|
||||
throw new ErrEntityNotFound(`not found entry in [${this.Name()}] for id [${id}]`)
|
||||
}
|
||||
|
||||
@@ -69,27 +69,31 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
async _findByParams(params: {}, limit?: number, order?: {}): Promise<T[]> {
|
||||
const cursor = await this._storage.find(this.Name(), params)
|
||||
async _findByParams(
|
||||
parameters: Record<string, unknown>,
|
||||
limit?: number,
|
||||
order?: Record<string, unknown>
|
||||
): Promise<T[]> {
|
||||
const cursor = await this._storage.find(this.Name(), parameters)
|
||||
if (limit && limit > 0) await cursor.limit(limit)
|
||||
if (order) await cursor.sort(order)
|
||||
const data = await cursor.toArray()
|
||||
const list = []
|
||||
for (let item of data) {
|
||||
for (const item of data) {
|
||||
list.push(this._transformer(item))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
async findMany(params: object, order?: object): Promise<T[]> {
|
||||
const cursor = await this._storage.find(this.Name(), params)
|
||||
async findMany(parameters: Record<string, unknown>, order?: Record<string, unknown>): Promise<T[]> {
|
||||
const cursor = await this._storage.find(this.Name(), parameters)
|
||||
if (this._offset > 0) await cursor.skip(this._offset)
|
||||
if (this._limit > 0) await cursor.limit(this._limit)
|
||||
if (order) await cursor.sort(order)
|
||||
const data = await cursor.toArray()
|
||||
const list = []
|
||||
for (let item of data) {
|
||||
for (const item of data) {
|
||||
list.push(this._transformer(item))
|
||||
}
|
||||
|
||||
@@ -102,7 +106,7 @@ export abstract class Repo<T extends Entity<any>> {
|
||||
return this
|
||||
}
|
||||
|
||||
async count(query?: object): Promise<number> {
|
||||
async count(query?: Record<string, unknown>): Promise<number> {
|
||||
return this._storage.count(this.Name(), query)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user