From 52de165a528244da6fad08d91790331d803159c9 Mon Sep 17 00:00:00 2001 From: David Arranz Date: Wed, 26 Jun 2024 13:18:22 +0200 Subject: [PATCH] . --- .../contexts/auth/application/authServices.ts | 29 +--- .../contexts/auth/domain/entities/AuthUser.ts | 16 +- .../controllers/AuthenticateController.ts | 38 +---- .../identity/presenter/Identity.presenter.ts | 6 +- .../login/presenter/Login.presenter.ts | 1 + .../infrastructure/mappers/authuser.mapper.ts | 6 +- .../sequelize/authUser.model.ts | 7 + .../catalog/domain/entities/Article.ts | 12 +- .../listArticles/ListArticlesController.ts | 14 +- .../infrastructure/mappers/article.mapper.ts | 32 ++-- .../infrastructure/sequelize/article.model.ts | 36 ++--- .../sequelize/article.model.ts.bak | 140 ++++++++++++++++++ .../sequelize/articleTraslation.model.ts.bak | 83 +++++++++++ .../sequelize/SequelizeRepository.ts | 27 ++-- .../infrastructure/sequelize/user.model.ts | 6 +- .../express/api/routes/auth.routes.ts | 5 +- .../application/dto/ILogin_Response.dto.ts | 1 + .../IListArticles_Response.dto.ts | 4 +- .../contexts/common/domain/entities/Name.ts | 15 +- 19 files changed, 343 insertions(+), 135 deletions(-) create mode 100644 server/src/contexts/catalog/infrastructure/sequelize/article.model.ts.bak create mode 100644 server/src/contexts/catalog/infrastructure/sequelize/articleTraslation.model.ts.bak diff --git a/server/src/contexts/auth/application/authServices.ts b/server/src/contexts/auth/application/authServices.ts index 941d1be..591568d 100644 --- a/server/src/contexts/auth/application/authServices.ts +++ b/server/src/contexts/auth/application/authServices.ts @@ -6,34 +6,9 @@ import { IAuthRepository } from "../domain/repository"; export const findUserByEmail = async ( email: Email, adapter: IAdapter, - repository: RepositoryBuilder, + repository: RepositoryBuilder ): Promise => { return await adapter .startTransaction() - .complete(async (t) => - repository({ transaction: t }).findUserByEmail(email), - ); + .complete(async (t) => 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("auth") - - this._authRepository = ; - } - - -} -*/ diff --git a/server/src/contexts/auth/domain/entities/AuthUser.ts b/server/src/contexts/auth/domain/entities/AuthUser.ts index 1c132d5..5eb42ec 100644 --- a/server/src/contexts/auth/domain/entities/AuthUser.ts +++ b/server/src/contexts/auth/domain/entities/AuthUser.ts @@ -1,11 +1,20 @@ import { Password } from "@/contexts/common/domain"; -import { AggregateRoot, Email, IDomainError, Name, Result, UniqueID } from "@shared/contexts"; +import { + AggregateRoot, + Email, + IDomainError, + Language, + Name, + Result, + UniqueID, +} from "@shared/contexts"; import { AuthUserRole } from "./AuthUserRole"; export interface IAuthUserProps { name: Name; email: Email; password: Password; + language: Language; roles: AuthUserRole[]; } @@ -14,6 +23,7 @@ export interface IAuthUser { name: Name; email: Email; password: Password; + language: Language; isUser: boolean; isAdmin: boolean; getRoles: () => AuthUserRole[]; @@ -51,6 +61,10 @@ export class AuthUser extends AggregateRoot implements IAuthUser return this.props.password; } + get language(): Language { + return this.props.language; + } + get isUser(): boolean { return this._hasRole(AuthUserRole.ROLE_USER); } diff --git a/server/src/contexts/auth/infrastructure/express/controllers/AuthenticateController.ts b/server/src/contexts/auth/infrastructure/express/controllers/AuthenticateController.ts index fe7e3e7..d9ea91e 100644 --- a/server/src/contexts/auth/infrastructure/express/controllers/AuthenticateController.ts +++ b/server/src/contexts/auth/infrastructure/express/controllers/AuthenticateController.ts @@ -4,37 +4,7 @@ import { IServerError } from "@/contexts/common/domain/errors"; import { ExpressController } from "@/contexts/common/infrastructure/express"; import passport from "passport"; -// Export a middleware function to authenticate incoming requests -/*export const authenticate = (req, res, next) => { - // Use Passport to authenticate the request using the "jwt" strategy - passport.authenticate("jwt", { session: false }, (err, user) => { - console.log(user); - if (err) next(err); // If there's an error, pass it on to the next middleware - if (!user) { - // If the user is not authenticated, send a 401 Unauthorized response - return res.status(401).json({ - message: "Unauthorized access. No token provided.", - }); - } - // If the user is authenticated, attach the user object to the request and move on to the next middleware - req.user = user; - next(); - })(req, res, next); -};*/ - export class AuthenticateController extends ExpressController { - //private context: AuthContext; - - constructor() { - //context: IAuthContext, - super(); - - /*const { useCase, presenter } = props; - this.useCase = useCase; - this.presenter = presenter; - this.context = context;*/ - } - async executeImpl() { try { return passport.authenticate( @@ -44,22 +14,20 @@ export class AuthenticateController extends ExpressController { err: any, user?: AuthUser | false | null, info?: object | string | Array, - status?: number | Array, + status?: number | Array ) => { if (err) { return this.next(err); } if (!user) { - return this.unauthorizedError( - "Unauthorized access. No token provided.", - ); + return this.unauthorizedError("Unauthorized access. No token provided."); } // If the user is authenticated, attach the user object to the request and move on to the next middleware this.req.user = user; return this.next(); - }, + } ); } catch (e: unknown) { return this.fail(e as IServerError); diff --git a/server/src/contexts/auth/infrastructure/express/controllers/identity/presenter/Identity.presenter.ts b/server/src/contexts/auth/infrastructure/express/controllers/identity/presenter/Identity.presenter.ts index 74a16a6..7c5b64a 100644 --- a/server/src/contexts/auth/infrastructure/express/controllers/identity/presenter/Identity.presenter.ts +++ b/server/src/contexts/auth/infrastructure/express/controllers/identity/presenter/Identity.presenter.ts @@ -2,9 +2,7 @@ import { IAuthUser } from "@/contexts/auth/domain"; import { IAuthContext } from "@/contexts/auth/infrastructure/Auth.context"; import { IIdentity_Response_DTO } from "@shared/contexts"; -export interface IIdentityUser extends IAuthUser { - language: string; -} +export interface IIdentityUser extends IAuthUser {} export interface IIdentityPresenter { map: (user: IIdentityUser, context: IAuthContext) => IIdentity_Response_DTO; @@ -17,7 +15,7 @@ export const identityPresenter: IIdentityPresenter = { id: user.id.toString(), name: user.name.toString(), email: user.email.toString(), - language: "es", + language: user.language.toString(), roles: user.getRoles()?.map((rol) => rol.toString()), }; }, diff --git a/server/src/contexts/auth/infrastructure/express/controllers/login/presenter/Login.presenter.ts b/server/src/contexts/auth/infrastructure/express/controllers/login/presenter/Login.presenter.ts index 226c0b4..9876025 100644 --- a/server/src/contexts/auth/infrastructure/express/controllers/login/presenter/Login.presenter.ts +++ b/server/src/contexts/auth/infrastructure/express/controllers/login/presenter/Login.presenter.ts @@ -22,6 +22,7 @@ export const loginPresenter: ILoginPresenter = { id: user.id.toString(), name: user.name.toString(), email: user.email.toString(), + lang_code: user.language.toString(), roles, token, refresh_token: refreshToken, diff --git a/server/src/contexts/auth/infrastructure/mappers/authuser.mapper.ts b/server/src/contexts/auth/infrastructure/mappers/authuser.mapper.ts index 835c0cc..3d2c65e 100644 --- a/server/src/contexts/auth/infrastructure/mappers/authuser.mapper.ts +++ b/server/src/contexts/auth/infrastructure/mappers/authuser.mapper.ts @@ -1,7 +1,7 @@ import { Password } from "@/contexts/common/domain"; import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure"; import { UserRole } from "@/contexts/users/domain"; -import { Email, Name, UniqueID } from "@shared/contexts"; +import { Email, Language, Name, UniqueID } from "@shared/contexts"; import { AuthUser, IAuthUserProps } from "../../domain/entities"; import { IAuthContext } from "../Auth.context"; import { AuthUserCreationAttributes, AuthUser_Model } from "../sequelize/authUser.model"; @@ -22,6 +22,9 @@ class AuthUserMapper name: this.mapsValue(source, "name", Name.create), email: this.mapsValue(source, "email", Email.create), password: this.mapsValue(source, "password", Password.createFromHashedTextPassword), + language: this.mapsValue(source, "lang_code", Language.createFromCode, { + defaultValue: Language.DEFAULT_LANGUAGE_CODE, + }), roles: source.roles.map((rol) => UserRole.create(rol).object), }; @@ -41,6 +44,7 @@ class AuthUserMapper name: source.name.toPrimitive(), email: source.email.toPrimitive(), password: source.password.toPrimitive(), + lang_code: source.language.toPrimitive(), roles: source.getRoles().map((role) => role.toPrimitive()), }; } diff --git a/server/src/contexts/auth/infrastructure/sequelize/authUser.model.ts b/server/src/contexts/auth/infrastructure/sequelize/authUser.model.ts index 9c80256..f20e1b1 100644 --- a/server/src/contexts/auth/infrastructure/sequelize/authUser.model.ts +++ b/server/src/contexts/auth/infrastructure/sequelize/authUser.model.ts @@ -19,6 +19,7 @@ export class AuthUser_Model extends Model< declare name: string; declare email: string; declare password: string; + declare lang_code: string; declare roles: string[]; } @@ -44,6 +45,12 @@ export default (sequelize: Sequelize) => { allowNull: false, }, + lang_code: { + type: DataTypes.STRING(2), + allowNull: false, + defaultValue: "es", + }, + roles: { type: DataTypes.STRING, allowNull: false, diff --git a/server/src/contexts/catalog/domain/entities/Article.ts b/server/src/contexts/catalog/domain/entities/Article.ts index ff7e501..d17eed0 100644 --- a/server/src/contexts/catalog/domain/entities/Article.ts +++ b/server/src/contexts/catalog/domain/entities/Article.ts @@ -2,6 +2,8 @@ import { AggregateRoot, Description, IDomainError, + Language, + Name, Quantity, Result, Slug, @@ -11,9 +13,10 @@ import { import { ArticleIdentifier } from "./ArticleIdentifier"; export interface IArticleProps { - catalog_name: Slug; + catalog_name: Name; id_article: ArticleIdentifier; reference: Slug; + language: Language; description: Description; points: Quantity; retail_price: UnitPrice; @@ -21,9 +24,10 @@ export interface IArticleProps { export interface IArticle { id: UniqueID; - catalog_name: Slug; + catalog_name: Name; id_article: ArticleIdentifier; reference: Slug; + language: Language; description: Description; points: Quantity; retail_price: UnitPrice; @@ -63,6 +67,10 @@ export class Article extends AggregateRoot implements IArticle { return this.props.reference; } + get language(): Language { + return this.props.language; + } + get description(): Description { return this.props.description; } diff --git a/server/src/contexts/catalog/infrastructure/express/controllers/listArticles/ListArticlesController.ts b/server/src/contexts/catalog/infrastructure/express/controllers/listArticles/ListArticlesController.ts index c41c0e2..8f09116 100644 --- a/server/src/contexts/catalog/infrastructure/express/controllers/listArticles/ListArticlesController.ts +++ b/server/src/contexts/catalog/infrastructure/express/controllers/listArticles/ListArticlesController.ts @@ -1,5 +1,6 @@ import Joi from "joi"; +import { AuthUser } from "@/contexts/auth/domain"; import { ListArticlesResult, ListArticlesUseCase } from "@/contexts/catalog/application"; import { Article } from "@/contexts/catalog/domain"; import { QueryCriteriaService } from "@/contexts/common/application/services"; @@ -10,6 +11,7 @@ import { IListArticles_Response_DTO, IListResponse_DTO, IQueryCriteria, + Language, Result, RuleValidator, } from "@shared/contexts"; @@ -49,7 +51,13 @@ export class ListArticlesController extends ExpressController { } async executeImpl() { - const queryOrError = this.validateQuery(this.req.query); + const { language = Language.createDefaultCode() } = this.req.user; + + const queryOrError = this.validateQuery({ + $filters: `lang_code[eq]${language.toString()}`, + ...this.req.query, + }); + if (queryOrError.isFailure) { return this.clientError(queryOrError.error.message); } @@ -67,10 +75,10 @@ export class ListArticlesController extends ExpressController { return this.clientError(result.error.message); } - const customers = >result.object; + const articles = >result.object; return this.ok>( - this.presenter.mapArray(customers, this.context, { + this.presenter.mapArray(articles, this.context, { page: queryCriteria.pagination.offset, limit: queryCriteria.pagination.limit, }) diff --git a/server/src/contexts/catalog/infrastructure/mappers/article.mapper.ts b/server/src/contexts/catalog/infrastructure/mappers/article.mapper.ts index 9e27e68..4dc3a1c 100644 --- a/server/src/contexts/catalog/infrastructure/mappers/article.mapper.ts +++ b/server/src/contexts/catalog/infrastructure/mappers/article.mapper.ts @@ -1,8 +1,8 @@ import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure"; -import { Description, Quantity, Slug, UniqueID, UnitPrice } from "@shared/contexts"; +import { Description, Language, Name, Quantity, Slug, UniqueID, UnitPrice } from "@shared/contexts"; import { ICatalogContext } from ".."; import { Article, ArticleIdentifier, IArticleProps } from "../../domain/entities"; -import { ArticleCreationAttributes, Article_Model } from "../sequelize/article.model"; +import { ArticleCreationAttributes, Article_Model } from "../sequelize"; export interface IArticleMapper extends ISequelizeMapper {} @@ -16,15 +16,27 @@ class ArticleMapper } protected toDomainMappingImpl(source: Article_Model, params: any): Article { + const catalog_name = this.mapsValue(source, "catalog_name", Name.create); + const id_article = this.mapsValue(source, "id_article", ArticleIdentifier.create); + const reference = this.mapsValue(source, "reference", Slug.create); + const points = this.mapsValue(source, "points", (value: any) => + Quantity.create({ amount: value, precision: 4 }) + ); + const retail_price = this.mapsValue(source, "retail_price", (value: any) => + UnitPrice.create({ amount: value, precision: 4 }) + ); + + const language = this.mapsValue(source, "lang_code", Language.createFromCode); + const description = this.mapsValue(source, "description", Description.create); + const props: IArticleProps = { - catalog_name: this.mapsValue(source, "catalog_name", Slug.create), - id_article: this.mapsValue(source, "id_article", ArticleIdentifier.create), - reference: this.mapsValue(source, "reference", Slug.create), - description: this.mapsValue(source, "description", Description.create), - points: this.mapsValue(source, "points", Quantity.create), - retail_price: this.mapsValue(source, "retail_price", (value: any) => - UnitPrice.create({ amount: value, precision: 4 }) - ), + catalog_name, + id_article, + reference, + points, + retail_price, + language, + description, }; const id = this.mapsValue(source, "id", UniqueID.create); diff --git a/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts b/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts index 1016006..6efb82b 100644 --- a/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts +++ b/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts @@ -15,9 +15,9 @@ export class Article_Model extends Model< InferCreationAttributes > { // To avoid table creation - /*static async sync(): Promise { + static async sync(): Promise { return Promise.resolve(); - }*/ + } static associate(connection: Sequelize) {} @@ -26,6 +26,7 @@ export class Article_Model extends Model< declare catalog_name: string; declare id_article: string; // number ?? declare reference: CreationOptional; + declare lang_code: CreationOptional; declare description: CreationOptional; declare points: CreationOptional; declare retail_price: CreationOptional; @@ -43,37 +44,38 @@ export default (sequelize: Sequelize) => { type: DataTypes.STRING(), allowNull: false, }, + id_article: { type: DataTypes.BIGINT().UNSIGNED, allowNull: false, }, + reference: DataTypes.STRING(), + + lang_code: { + type: DataTypes.STRING(2), + allowNull: false, + defaultValue: "es", + }, + description: DataTypes.STRING(), + points: { - type: DataTypes.SMALLINT().UNSIGNED, + type: DataTypes.BIGINT().UNSIGNED, defaultValue: 0, }, + retail_price: DataTypes.BIGINT(), }, { sequelize, - tableName: "catalog", + tableName: "v_catalog", - //paranoid: true, // softs deletes - timestamps: true, - //version: true, - - createdAt: "created_at", - updatedAt: "updated_at", - deletedAt: "deleted_at", - - indexes: [ - { name: "catalog_name_idx", fields: ["catalog_name"] }, - { name: "id_article_idx", fields: ["id_article"] }, - { name: "updated_at_idx", fields: ["updated_at"] }, - ], + paranoid: true, // softs deletes + timestamps: false, whereMergeStrategy: "and", // <- cómo tratar el merge de un scope + scopes: { quickSearch(value) { return { diff --git a/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts.bak b/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts.bak new file mode 100644 index 0000000..e8e2704 --- /dev/null +++ b/server/src/contexts/catalog/infrastructure/sequelize/article.model.ts.bak @@ -0,0 +1,140 @@ +import { + CreationOptional, + DataTypes, + InferAttributes, + InferCreationAttributes, + Model, + NonAttribute, + Op, + Sequelize, +} from "sequelize"; +import { ArticleTranslation_Model } from "./articleTraslation.model.ts.bak"; + +export type ArticleCreationAttributes = InferCreationAttributes< + Article_Model, + { + omit: "translations"; + } +>; + +export class Article_Model extends Model< + InferAttributes, + InferCreationAttributes +> { + // To avoid table creation + static async sync(): Promise { + return Promise.resolve(); + } + + static associate(connection: Sequelize) { + const { Article_Model, ArticleTranslation_Model } = connection.models; + + Article_Model.hasMany(ArticleTranslation_Model, { + as: "translations", + foreignKey: "catalog_id", + onDelete: "CASCADE", + }); + } + + declare id: string; + + declare catalog_name: string; + declare id_article: string; // number ?? + declare reference: CreationOptional; + //declare description: CreationOptional; + declare points: CreationOptional; + declare retail_price: CreationOptional; + + declare translations?: NonAttribute; +} + +export default (sequelize: Sequelize) => { + Article_Model.init( + { + id: { + type: new DataTypes.UUID(), + primaryKey: true, + }, + + catalog_name: { + type: DataTypes.STRING(), + allowNull: false, + }, + + id_article: { + type: DataTypes.BIGINT().UNSIGNED, + allowNull: false, + }, + + reference: DataTypes.STRING(), + //description: DataTypes.STRING(), + points: { + type: DataTypes.BIGINT().UNSIGNED, + defaultValue: 0, + }, + + retail_price: DataTypes.BIGINT(), + }, + { + sequelize, + tableName: "catalog", + + paranoid: true, // softs deletes + timestamps: true, + //version: true, + + createdAt: "created_at", + updatedAt: "updated_at", + deletedAt: "deleted_at", + + indexes: [ + { name: "catalog_name_idx", fields: ["catalog_name"] }, + { name: "id_article_idx", fields: ["id_article"] }, + { name: "updated_at_idx", fields: ["updated_at"] }, + ], + + whereMergeStrategy: "and", // <- cómo tratar el merge de un scope + + defaultScope: { + attributes: { exclude: ["id_article", "reference"] }, + include: [ + { + attributes: ["description"], + model: ArticleTranslation_Model, + as: "translations", + required: true, + where: { + lang_code: "es", + }, + }, + ], + }, + + scopes: { + quickSearch(value) { + return { + include: [ + { + model: ArticleTranslation_Model, + as: "translations", + required: true, + where: { + [Op.or]: { + reference: { + [Op.like]: `%${value}%`, + }, + description: { + [Op.like]: `%${value}%`, + }, + }, + }, + }, + ], + }; + }, + }, + } + ); + + return Article_Model; +}; diff --git a/server/src/contexts/catalog/infrastructure/sequelize/articleTraslation.model.ts.bak b/server/src/contexts/catalog/infrastructure/sequelize/articleTraslation.model.ts.bak new file mode 100644 index 0000000..e8e6156 --- /dev/null +++ b/server/src/contexts/catalog/infrastructure/sequelize/articleTraslation.model.ts.bak @@ -0,0 +1,83 @@ +import { + CreationOptional, + DataTypes, + InferAttributes, + InferCreationAttributes, + Model, + Op, + Sequelize, +} from "sequelize"; + +export type ArticleTranslationCreationAttributes = + InferCreationAttributes; + +export class ArticleTranslation_Model extends Model< + InferAttributes, + InferCreationAttributes +> { + // To avoid table creation + /*static async sync(): Promise { + return Promise.resolve(); + }*/ + + static associate(connection: Sequelize) { + const { Article_Model, ArticleTranslation_Model } = connection.models; + + ArticleTranslation_Model.belongsTo(Article_Model, { + as: "translations", + foreignKey: "catalog_id", + onDelete: "CASCADE", + }); + } + + declare id: string; + + declare lang_code: CreationOptional; + declare description: CreationOptional; +} + +export default (sequelize: Sequelize) => { + ArticleTranslation_Model.init( + { + id: { + type: new DataTypes.UUID(), + primaryKey: true, + }, + + lang_code: { + type: DataTypes.STRING(2), + allowNull: false, + defaultValue: "es", + }, + + description: DataTypes.STRING(), + }, + { + sequelize, + tableName: "catalog_translations", + + //paranoid: true, // softs deletes + timestamps: false, + //version: true, + + indexes: [{ name: "lang_code_idx", fields: ["lang_code"] }], + + whereMergeStrategy: "and", // <- cómo tratar el merge de un scope + scopes: { + quickSearch(value) { + return { + where: { + [Op.or]: { + description: { + [Op.like]: `%${value}%`, + }, + }, + }, + }; + }, + }, + } + ); + + return ArticleTranslation_Model; +}; diff --git a/server/src/contexts/common/infrastructure/sequelize/SequelizeRepository.ts b/server/src/contexts/common/infrastructure/sequelize/SequelizeRepository.ts index 043d90f..f646422 100644 --- a/server/src/contexts/common/infrastructure/sequelize/SequelizeRepository.ts +++ b/server/src/contexts/common/infrastructure/sequelize/SequelizeRepository.ts @@ -9,10 +9,7 @@ export abstract class SequelizeRepository implements IRepository { protected _transaction: Transaction; protected _adapter: ISequelizeAdapter; - public constructor(props: { - adapter: ISequelizeAdapter; - transaction: Transaction; - }) { + public constructor(props: { adapter: ISequelizeAdapter; transaction: Transaction }) { this._adapter = props.adapter; this._transaction = props.transaction; } @@ -49,7 +46,7 @@ export abstract class SequelizeRepository implements IRepository { modelName: string, field: string, value: any, - params: any = {}, + params: any = {} ): Promise { const _model = this._adapter.getModel(modelName); const where: { [key: string]: any } = {}; @@ -63,11 +60,7 @@ export abstract class SequelizeRepository implements IRepository { }); } - protected async _getById( - modelName: string, - id: UniqueID | string, - params: any = {}, - ): Promise { + protected async _getById(modelName: string, id: UniqueID | string, params: any = {}): Promise { const _model = this._adapter.getModel(modelName); return _model.findByPk(id.toString(), params); } @@ -75,7 +68,7 @@ export abstract class SequelizeRepository implements IRepository { protected async _findAll( modelName: string, queryCriteria?: IQueryCriteria, - params: any = {}, + params: any = {} ): Promise<{ rows: any[]; count: number }> { console.time("_findAll"); @@ -84,6 +77,8 @@ export abstract class SequelizeRepository implements IRepository { queryCriteria, }); + console.log(query); + const args = { ...query, distinct: true, @@ -102,7 +97,7 @@ export abstract class SequelizeRepository implements IRepository { modelName: string, field: string, value: any, - params: any = {}, + params: any = {} ): Promise { const _model = this._adapter.getModel(modelName) as ModelDefined; const where = {}; @@ -120,7 +115,7 @@ export abstract class SequelizeRepository implements IRepository { modelName: string, id: UniqueID, data: any, - params: any = {}, + params: any = {} ): Promise { const _model = this._adapter.getModel(modelName); @@ -134,7 +129,7 @@ export abstract class SequelizeRepository implements IRepository { where: { id: id.toPrimitive() }, transaction: this._transaction, ...params, - }, + } ); } else { await _model.create( @@ -146,7 +141,7 @@ export abstract class SequelizeRepository implements IRepository { include: [{ all: true }], transaction: this._transaction, ...params, - }, + } ); } } @@ -155,7 +150,7 @@ export abstract class SequelizeRepository implements IRepository { modelName: string, id: UniqueID, force: boolean = false, - params: any = {}, + params: any = {} ): Promise { const model: ModelDefined = this._adapter.getModel(modelName); diff --git a/server/src/contexts/users/infrastructure/sequelize/user.model.ts b/server/src/contexts/users/infrastructure/sequelize/user.model.ts index 6260ac8..19e080d 100644 --- a/server/src/contexts/users/infrastructure/sequelize/user.model.ts +++ b/server/src/contexts/users/infrastructure/sequelize/user.model.ts @@ -38,7 +38,7 @@ export class User_Model extends Model< declare name: string; declare email: string; declare password: string; - declare language: string; + declare lang_code: string; declare roles: string[]; } @@ -64,8 +64,8 @@ export default (sequelize: Sequelize) => { allowNull: false, }, - language: { - type: DataTypes.STRING, + lang_code: { + type: DataTypes.STRING(2), allowNull: false, defaultValue: "es", }, diff --git a/server/src/infrastructure/express/api/routes/auth.routes.ts b/server/src/infrastructure/express/api/routes/auth.routes.ts index dd5990b..1ef95ba 100644 --- a/server/src/infrastructure/express/api/routes/auth.routes.ts +++ b/server/src/infrastructure/express/api/routes/auth.routes.ts @@ -1,8 +1,7 @@ +import { checkUser, createLoginController } from "@/contexts/auth"; +import { createIdentityController } from "@/contexts/auth/infrastructure/express/controllers/identity"; import Express from "express"; import passport from "passport"; -import { createLoginController } from "../../../../contexts/auth/infrastructure/express/controllers"; -import { createIdentityController } from "../../../../contexts/auth/infrastructure/express/controllers/identity"; -import { checkUser } from "../../../../contexts/auth/infrastructure/express/passport"; export const authRouter = (appRouter: Express.Router) => { const authRoutes: Express.Router = Express.Router({ mergeParams: true }); diff --git a/shared/lib/contexts/auth/application/dto/ILogin_Response.dto.ts b/shared/lib/contexts/auth/application/dto/ILogin_Response.dto.ts index d095a51..e8dd765 100644 --- a/shared/lib/contexts/auth/application/dto/ILogin_Response.dto.ts +++ b/shared/lib/contexts/auth/application/dto/ILogin_Response.dto.ts @@ -2,6 +2,7 @@ export interface ILogin_Response_DTO { id: string; name: string; email: string; + lang_code: string; roles: string[]; token: string; refresh_token: string; diff --git a/shared/lib/contexts/catalog/application/dto/IListArticles.dto/IListArticles_Response.dto.ts b/shared/lib/contexts/catalog/application/dto/IListArticles.dto/IListArticles_Response.dto.ts index 6ec0f4a..a01d882 100644 --- a/shared/lib/contexts/catalog/application/dto/IListArticles.dto/IListArticles_Response.dto.ts +++ b/shared/lib/contexts/catalog/application/dto/IListArticles.dto/IListArticles_Response.dto.ts @@ -3,8 +3,8 @@ import { IMoney_Response_DTO } from "../../../../common"; export interface IListArticles_Response_DTO { id: string; catalog_name: string; - id_article: string; - reference: string; + //id_article: string; + //reference: string; //family: string; //subfamily: string; description: string; diff --git a/shared/lib/contexts/common/domain/entities/Name.ts b/shared/lib/contexts/common/domain/entities/Name.ts index 9d978c5..b9ad8a2 100644 --- a/shared/lib/contexts/common/domain/entities/Name.ts +++ b/shared/lib/contexts/common/domain/entities/Name.ts @@ -3,15 +3,12 @@ import { UndefinedOr } from "../../../../utilities"; import { RuleValidator } from "../RuleValidator"; import { DomainError, handleDomainError } from "../errors"; import { Result } from "./Result"; -import { - IStringValueObjectOptions, - StringValueObject, -} from "./StringValueObject"; +import { IStringValueObjectOptions, StringValueObject } from "./StringValueObject"; export interface INameOptions extends IStringValueObjectOptions {} export class Name extends StringValueObject { - private static readonly MIN_LENGTH = 2; + //private static readonly MIN_LENGTH = 1; private static readonly MAX_LENGTH = 100; protected static validate(value: UndefinedOr, options: INameOptions) { @@ -20,7 +17,7 @@ export class Name extends StringValueObject { .allow("") .default("") .trim() - .min(Name.MIN_LENGTH) + //.min(Name.MIN_LENGTH) .max(Name.MAX_LENGTH) .label(options.label ? options.label : "value"); @@ -37,11 +34,7 @@ export class Name extends StringValueObject { if (validationResult.isFailure) { return Result.fail( - handleDomainError( - DomainError.INVALID_INPUT_DATA, - validationResult.error.message, - _options - ) + handleDomainError(DomainError.INVALID_INPUT_DATA, validationResult.error.message, _options) ); }