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