@nestjs/common#HttpService TypeScript Examples

The following examples show how to use @nestjs/common#HttpService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.service.ts    From 42_checkIn with GNU General Public License v3.0 7 votes vote down vote up
constructor(
    private readonly authService: AuthService,
    private readonly userRepository: UserRepository,
    private readonly cardRepository: CardRepository,
    @Inject(forwardRef(() => CardService))
    private readonly cardServcie: CardService,
    private readonly logService: LogService,
    private readonly logger: MyLogger,
    private readonly configService: ConfigService,
    private readonly httpService: HttpService,
    private readonly waitingService: WaitingService,
    private readonly waitingRepository: WaitingRepository,
  ) {}
Example #2
Source File: consul.module.ts    From nestjs-consul with MIT License 6 votes vote down vote up
static forRoot<T>(config: IConsulConfig<T>): DynamicModule {
		const consulServiceProvider: Provider = {
			provide: ConsulService,
			useFactory: async () => {
				const consulService = new ConsulService<T>(config, new HttpService());
				if (config.keys) {
					await consulService.update();
				}
				return consulService;
			},
		};
		return {
			module: ConsulModule,
			providers: [consulServiceProvider],
			exports: [consulServiceProvider],
		};
	}
Example #3
Source File: consul.module.ts    From nestjs-consul with MIT License 6 votes vote down vote up
private static createAsyncOptionsProvider<T>(
		options: IConsulAsyncConfig<T>,
	): Provider {
		return {
			provide: ConsulService,
			useFactory: async (...args: any[]) => {
				const config = await options.useFactory(...args);
				const consulService = new ConsulService<T>(config, new HttpService());
				if (config.keys) {
					await consulService.update();
				}
				return consulService;
			},
			inject: options.inject || [],
		};
	}
Example #4
Source File: app.service.ts    From 42_checkIn with GNU General Public License v3.0 5 votes vote down vote up
constructor(
    private readonly httpService: HttpService,
    private readonly authService: AuthService,
  ) {}
Example #5
Source File: auth.service.ts    From 42_checkIn with GNU General Public License v3.0 5 votes vote down vote up
constructor(
    private readonly configService: ConfigService,
    private readonly jwtService: JwtService,
    private readonly httpService: HttpService,
    private readonly logger: MyLogger,
  ) {}
Example #6
Source File: consul.service.ts    From nestjs-consul with MIT License 5 votes vote down vote up
constructor({ connection, keys, updateCron }: IConsulConfig<T>, private readonly httpService: HttpService) {
		this.consulURL = `${connection.protocol}://${connection.host}:${connection.port}/v1/kv/`;
		this.keys = keys;
		this.token = connection.token;
		this.planUpdate(updateCron);
	}
Example #7
Source File: google-recaptcha.validator.ts    From google-recaptcha with MIT License 5 votes vote down vote up
constructor(@Inject(RECAPTCHA_HTTP_SERVICE) private readonly http: HttpService,
                @Inject(RECAPTCHA_OPTIONS) private readonly options: GoogleRecaptchaValidatorOptions) {
    }
Example #8
Source File: create-google-recaptcha-validator.ts    From google-recaptcha with MIT License 5 votes vote down vote up
export function createGoogleRecaptchaValidator(options: GoogleRecaptchaValidatorOptions): GoogleRecaptchaValidator {
    return new GoogleRecaptchaValidator(new HttpService(), options);
}
Example #9
Source File: currency.service.ts    From bank-server with MIT License 5 votes vote down vote up
constructor(
    private readonly _currencyRepository: CurrencyRepository,
    private readonly _httpService: HttpService,
  ) {}
Example #10
Source File: release-notes.controller.ts    From office-hours with GNU General Public License v3.0 5 votes vote down vote up
constructor(
    private connection: Connection,
    private httpService: HttpService,
  ) {}
Example #11
Source File: resources.controller.ts    From office-hours with GNU General Public License v3.0 5 votes vote down vote up
constructor(
    private connection: Connection,
    private httpService: HttpService,
    private resourcesService: ResourcesService,
  ) {}
Example #12
Source File: resources.service.ts    From office-hours with GNU General Public License v3.0 5 votes vote down vote up
constructor(
    private connection: Connection,
    private httpService: HttpService,
    private readonly redisService: RedisService,
  ) {}
Example #13
Source File: google-recaptcha-async-module.spec.ts    From google-recaptcha with MIT License 4 votes vote down vote up
describe('Google recaptcha async module', () => {
    const checkDefaultConfigs = (defaults: AxiosRequestConfig) => {
        expect(defaults).toBeDefined();
        expect(defaults.proxy).toBeDefined();

        const proxy: AxiosProxyConfig = defaults.proxy as AxiosProxyConfig;

        expect(proxy).toBeDefined();
        expect(typeof proxy).toBe('object');
        expect(proxy.host).toBe('TEST_PROXY_HOST');
        expect(proxy.port).toBe(7777);
    };

    test('Test via import module and use default axios config',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    imports: [
                        HttpModule.register({
                            proxy: {
                                host: 'TEST_PROXY_HOST',
                                port: 7777,
                            },
                            data: 'TEST',
                            timeout: 1000000000,
                        }),
                        TestConfigModule,
                    ],
                    useFactory: (config: TestConfigService, http: HttpService) => ({
                        ...config.getGoogleRecaptchaOptions(),
                        axiosConfig: http.axiosRef.defaults,
                    }),
                    inject: [
                        TestConfigService,
                        HttpService,
                    ],
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        await app.init();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);

        const axiosInstance: AxiosInstance = app.get(RECAPTCHA_AXIOS_INSTANCE);

        checkDefaultConfigs(axiosInstance.defaults);

        expect(axiosInstance.defaults.data).toBeUndefined();

        const options: GoogleRecaptchaModuleOptions = app.get(RECAPTCHA_OPTIONS);

        expect(options).toBeDefined();

        checkDefaultConfigs(options.axiosConfig);

        expect(options.axiosConfig.data).toBe('TEST');
    });

    test('Test via useClass',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    useClass: GoogleRecaptchaModuleOptionsFactory,
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);
    });

    test('Test via useExisting',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    imports: [
                        TestConfigModule,
                    ],
                    useExisting: GoogleRecaptchaModuleOptionsFactory,
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);
    });

    test('Test via useClass that not implement GoogleRecaptchaOptionsFactory',  async () => {
        await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    useClass: TestConfigModule as any,
                }),
            ],
        }).compile()
            .then(() => expect(true).toBeFalsy())
            .catch(e => expect(e.message).toBe('Factory must be implement \'GoogleRecaptchaOptionsFactory\' interface.'));
    });
});