.
This commit is contained in:
parent
42320f2012
commit
c2550e57f2
@ -14,3 +14,26 @@ export const findUserByEmail = async (
|
|||||||
repository({ transaction: t }).findUserByEmail(email),
|
repository({ transaction: t }).findUserByEmail(email),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*export class AuthService extends ApplicationService {
|
||||||
|
private _adapter: ISequelizeAdapter;
|
||||||
|
private _repository: IRepositoryManager;
|
||||||
|
private _authRepository: IAuthRepository;
|
||||||
|
|
||||||
|
constructor(props: {
|
||||||
|
adapter: ISequelizeAdapter,
|
||||||
|
repository: IRepositoryManager,
|
||||||
|
}) {
|
||||||
|
super();
|
||||||
|
this._adapter = props.adapter;
|
||||||
|
|
||||||
|
this._repository = props.repository;
|
||||||
|
|
||||||
|
this._repository.getRepository<IAuthRepository>("auth")
|
||||||
|
|
||||||
|
this._authRepository = ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
export * from './QueryCriteriaService';
|
export * from "./ApplicationService";
|
||||||
|
export * from "./QueryCriteriaService";
|
||||||
|
|||||||
@ -4,19 +4,17 @@ import { ModelDefined, Transaction } from "sequelize";
|
|||||||
|
|
||||||
import { IRepository } from "../../domain/repositories";
|
import { IRepository } from "../../domain/repositories";
|
||||||
import { ISequelizeAdapter } from "./SequelizeAdapter";
|
import { ISequelizeAdapter } from "./SequelizeAdapter";
|
||||||
import { ISequelizeQueryBuilder } from "./queryBuilder/SequelizeQueryBuilder";
|
|
||||||
|
|
||||||
export abstract class SequelizeRepository<T> implements IRepository<T> {
|
export abstract class SequelizeRepository<T> implements IRepository<T> {
|
||||||
protected queryBuilder: ISequelizeQueryBuilder;
|
protected _transaction: Transaction;
|
||||||
protected transaction: Transaction;
|
protected _adapter: ISequelizeAdapter;
|
||||||
protected adapter: ISequelizeAdapter;
|
|
||||||
public constructor(props: {
|
public constructor(props: {
|
||||||
adapter: ISequelizeAdapter;
|
adapter: ISequelizeAdapter;
|
||||||
transaction: Transaction;
|
transaction: Transaction;
|
||||||
}) {
|
}) {
|
||||||
this.adapter = props.adapter;
|
this._adapter = props.adapter;
|
||||||
this.transaction = props.transaction;
|
this._transaction = props.transaction;
|
||||||
this.queryBuilder = this.adapter.queryBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getById(id: UniqueID): Promise<T | null> {
|
protected getById(id: UniqueID): Promise<T | null> {
|
||||||
@ -53,14 +51,14 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
value: any,
|
value: any,
|
||||||
params: any = {},
|
params: any = {},
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const _model = this.adapter.getModel(modelName);
|
const _model = this._adapter.getModel(modelName);
|
||||||
const where: { [key: string]: any } = {};
|
const where: { [key: string]: any } = {};
|
||||||
|
|
||||||
where[field] = value;
|
where[field] = value;
|
||||||
|
|
||||||
return _model.findOne({
|
return _model.findOne({
|
||||||
where,
|
where,
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -70,7 +68,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
id: UniqueID | string,
|
id: UniqueID | string,
|
||||||
params: any = {},
|
params: any = {},
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const _model = this.adapter.getModel(modelName);
|
const _model = this._adapter.getModel(modelName);
|
||||||
return _model.findByPk(id.toString(), params);
|
return _model.findByPk(id.toString(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,15 +79,15 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
): Promise<{ rows: any[]; count: number }> {
|
): Promise<{ rows: any[]; count: number }> {
|
||||||
console.time("_findAll");
|
console.time("_findAll");
|
||||||
|
|
||||||
const { model: _model, query } = this.queryBuilder.generateQuery({
|
const { model: _model, query } = this._adapter.queryBuilder.generateQuery({
|
||||||
model: this.adapter.getModel(modelName),
|
model: this._adapter.getModel(modelName),
|
||||||
queryCriteria,
|
queryCriteria,
|
||||||
});
|
});
|
||||||
|
|
||||||
const args = {
|
const args = {
|
||||||
...query,
|
...query,
|
||||||
distinct: true,
|
distinct: true,
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
...params,
|
...params,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,13 +104,13 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
value: any,
|
value: any,
|
||||||
params: any = {},
|
params: any = {},
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const _model = this.adapter.getModel(modelName) as ModelDefined<any, any>;
|
const _model = this._adapter.getModel(modelName) as ModelDefined<any, any>;
|
||||||
const where = {};
|
const where = {};
|
||||||
where[field] = value;
|
where[field] = value;
|
||||||
|
|
||||||
const count: number = await _model.count({
|
const count: number = await _model.count({
|
||||||
where,
|
where,
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.resolve(Boolean(count !== 0));
|
return Promise.resolve(Boolean(count !== 0));
|
||||||
@ -124,7 +122,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
data: any,
|
data: any,
|
||||||
params: any = {},
|
params: any = {},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const _model = this.adapter.getModel(modelName);
|
const _model = this._adapter.getModel(modelName);
|
||||||
|
|
||||||
if (await this._exists(modelName, "id", id.toPrimitive())) {
|
if (await this._exists(modelName, "id", id.toPrimitive())) {
|
||||||
await _model.update(
|
await _model.update(
|
||||||
@ -134,7 +132,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
where: { id: id.toPrimitive() },
|
where: { id: id.toPrimitive() },
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -146,7 +144,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
include: [{ all: true }],
|
include: [{ all: true }],
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -159,13 +157,13 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
|||||||
force: boolean = false,
|
force: boolean = false,
|
||||||
params: any = {},
|
params: any = {},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const model: ModelDefined<any, any> = this.adapter.getModel(modelName);
|
const model: ModelDefined<any, any> = this._adapter.getModel(modelName);
|
||||||
|
|
||||||
await model.destroy({
|
await model.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: id.toPrimitive(),
|
id: id.toPrimitive(),
|
||||||
},
|
},
|
||||||
transaction: this.transaction,
|
transaction: this._transaction,
|
||||||
force,
|
force,
|
||||||
logging: console.log,
|
logging: console.log,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user