Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { CurlModule } from './core/curl/curl.module';
import { UploadFileModule } from './core/upload-file/upload-file.module';
import { FileModule } from './file/file.module';
import { RoleModule } from './core/role/role.module';
import { ResourceModule } from './core/resource/resource.module';
import * as path from 'path';
const entitiesPath =
process.env.NODE_ENV === 'production'
? path.resolve('./**/*.entity.js')
: path.resolve('./**/*.entity.ts');
Logger.log(process.env.NODE_ENV, '当前环境');
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}'), {
modifyConfigName: name => name.replace('.config', ''),
}), // 配置加载配置文件
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
type: config.get('database.type'),
host: config.get('database.host'),
port: config.get('database.port'),
username: config.get('database.username'),
password: config.get('database.password'),
database: config.get('database.database'),
entities: [entitiesPath],
synchronize: config.get('database.synchronize'),
logging: config.get('database.logging'),
}),
inject: [ConfigService],
}),
it('Does it instance with options using async registry', async () => {
const module = await Test.createTestingModule({
imports: [
ConfigModule.load(
path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
),
BraintreeModule.forRootAsync({
useFactory: config => config.get('braintree'),
inject: [ConfigService],
}),
],
}).compile();
const options = module.get(BRAINTREE_OPTIONS_PROVIDER);
const provider = module.get(BraintreeProvider);
expect(options.environment).toBe(braintree.Environment.Sandbox);
expect(typeof options.merchantId).toBe('string');
expect(typeof options.publicKey).toBe('string');
expect(typeof options.privateKey).toBe('string');
@BraintreeWebhookHandler()
class TestProvider {
@BraintreeSubscriptionCanceled()
canceled() {
return true;
}
@BraintreeSubscriptionChargedSuccessfully()
callMe() {
throw new Error('hello I am errors');
}
}
module = await Test.createTestingModule({
imports: [
ConfigModule.load(
path.resolve(__dirname, '../', '__stubs__', 'config', '*.ts'),
),
BraintreeModule.forRoot({
environment: braintree.Environment.Sandbox,
merchantId: 'merchantId',
publicKey: 'publicKey',
privateKey: 'privateKey',
}),
BraintreeWebhookModule,
],
providers: [TestProvider],
}).compile();
app = module.createNestApplication();
await app.init();
});
class SubscriptionProvider {
public static called = false;
@BraintreeSubscriptionCanceled()
canceled(webhook) {
//this is a work around the jest spyon reflect issue
SubscriptionProvider.called = true;
}
@BraintreeSubscriptionExpired()
expired(webhook) {}
}
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.load(
path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
),
BraintreeModule.forRootAsync({
useFactory: async config => config.get('braintree'),
inject: [ConfigService],
}),
BraintreeWebhookModule,
],
providers: [SubscriptionProvider],
}).compile();
const gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: 'merchantId',
publicKey: 'publicKey',
privateKey: 'privateKey',
beforeEach(async () => {
module = await Test.createTestingModule({
imports: [
ConfigModule.load(
path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
),
BraintreeModule.forRootAsync({
useFactory: async config => config.get('braintree'),
inject: [ConfigService],
}),
],
}).compile();
provider = module.get(BraintreeProvider);
});
beforeEach(async () => {
module = await Test.createTestingModule({
imports: [
ConfigModule.load(
path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
),
BraintreeModule.forRootAsync({
useFactory: async config => config.get('braintree'),
inject: [ConfigService],
}),
BraintreeWebhookModule,
],
providers: [SubscriptionProvider],
}).compile();
});
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import * as path from 'path';
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '*.{ts,js}')),
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => config.get('database'),
inject: [ConfigService],
}),
UserModule
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Module } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config';
import * as path from 'path';
import UserController from './user.controller';
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
],
controllers: [UserController],
})
export default class UserModule {}
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config/**/!(*.d).{ts,js}')),
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => config.get('database'),
inject: [ConfigService],
}),
],
})
export default class AppModule {}
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { logger, LoggerMiddleware } from './middlewares/logger.middleware';
import { CatsController } from './cats/cats.controller';
import { CatsModule } from './cats/cats.module';
@Module({
imports: [ConfigModule.load(), CatsModule],
controllers: [AppController],
providers: [AppService],
})
export class ApplicationModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(logger).forRoutes(CatsController);
}
}