import { AssemblerSerializer , AssemblerDeserializer , getQueryServiceToken } from '@nestjs-query/core' ; import { FactoryProvider } from '@nestjs/common' ; import { ModelCtor , Model , SequelizeOptions } from 'sequelize-typescript' ; import { getModelToken } from '@nestjs/sequelize' ; import { SequelizeQueryService } from './services' ; function createSequelizeQueryServiceProvider < Entity extends Model > ( EntityClass , connection ? ) { return { provide : getQueryServiceToken ( EntityClass ) , useFactory ( entity ) { AssemblerSerializer < Entity > ( ( instance ) => instance . get ( { plain : true } ) as Entity ) ( entity ) ; AssemblerDeserializer < Entity > ( ( obj ) => entity . build ( obj ) ) ( entity ) ; return new SequelizeQueryService ( entity ) ; } , inject : [ getModelToken ( EntityClass , connection ) ] , } ; } export const createSequelizeQueryServiceProviders = ( entities , connection ? ) : FactoryProvider [ ] => entities . map ( ( entity ) => createSequelizeQueryServiceProvider ( entity , connection ) ) ;