This commit is contained in:
David Arranz 2024-05-09 13:51:24 +02:00
parent e4d403472d
commit 09ab90f923
3 changed files with 20 additions and 27 deletions

View File

@ -67,7 +67,7 @@
"path": "^0.12.7", "path": "^0.12.7",
"remove": "^0.1.5", "remove": "^0.1.5",
"response-time": "^2.3.2", "response-time": "^2.3.2",
"sequelize": "^6.33.0", "sequelize": "^6.37.3",
"sequelize-revision": "^6.0.0", "sequelize-revision": "^6.0.0",
"sequelize-typescript": "^2.1.5", "sequelize-typescript": "^2.1.5",
"shallow-equal-object": "^1.1.1", "shallow-equal-object": "^1.1.1",

View File

@ -80,32 +80,25 @@ export default (sequelize: Sequelize) => {
{ name: "updated_at_idx", fields: ["updated_at"] }, { name: "updated_at_idx", fields: ["updated_at"] },
], ],
whereMergeStrategy: "and",
scopes: { scopes: {
quickSearch(value) { quickSearch(value) {
return { return {
where: { where: {
[Op.or]: [ [Op.or]: {
{ reference: {
reference: { [Op.like]: `%${value}%`,
[Op.like]: `%${value}%`,
},
}, },
{ family: {
family: { [Op.like]: `%${value}%`,
[Op.like]: `%${value}%`,
},
}, },
{ subfamily: {
subfamily: { [Op.like]: `%${value}%`,
[Op.like]: `%${value}%`,
},
}, },
{ description: {
description: { [Op.like]: `%${value}%`,
[Op.like]: `%${value}%`,
},
}, },
], },
}, },
}; };
}, },

View File

@ -51,7 +51,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
modelName: string, modelName: string,
field: string, field: string,
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 } = {};
@ -68,7 +68,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
protected async _getById( protected async _getById(
modelName: string, modelName: string,
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);
@ -77,7 +77,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
protected async _findAll( protected async _findAll(
modelName: string, modelName: string,
queryCriteria?: IQueryCriteria, queryCriteria?: IQueryCriteria,
params: any = {} params: any = {},
): Promise<{ rows: any[]; count: number }> { ): Promise<{ rows: any[]; count: number }> {
console.time("_findAll"); console.time("_findAll");
@ -108,7 +108,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
modelName: string, modelName: string,
field: string, field: string,
value: any, value: any,
params: any = {} params: any = {},
): Promise<boolean> { ): Promise<boolean> {
const _model = this.adapter.getModel(modelName); const _model = this.adapter.getModel(modelName);
const where = {}; const where = {};
@ -126,7 +126,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
modelName: string, modelName: string,
id: UniqueID, id: UniqueID,
data: any, data: any,
params: any = {} params: any = {},
): Promise<void> { ): Promise<void> {
const _model = this.adapter.getModel(modelName); const _model = this.adapter.getModel(modelName);
@ -140,7 +140,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
where: { id: id.toString() }, where: { id: id.toString() },
transaction: this.transaction, transaction: this.transaction,
...params, ...params,
} },
); );
} else { } else {
await _model.create( await _model.create(
@ -152,7 +152,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
include: [{ all: true }], include: [{ all: true }],
transaction: this.transaction, transaction: this.transaction,
...params, ...params,
} },
); );
} }
} }
@ -161,7 +161,7 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
modelName: string, modelName: string,
id: UniqueID, id: UniqueID,
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);