Skip to content

Commit

Permalink
fix(工具模块): 提交获取redis配置
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayisheji committed Feb 21, 2019
1 parent 5d7c35a commit b49736e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/shared/mongodb/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export abstract class BaseService<T extends Document> {
page: 1,
pages: 0,
};
const { offset, page, option } = options;
const { offset, page, option } = options || { offset: 0, page: 1, option: {}};
if (offset !== undefined) {
result.offset = options.offset;
options.skip = offset;
Expand Down Expand Up @@ -136,8 +136,8 @@ export abstract class BaseService<T extends Document> {
populates?: ModelPopulateOptions[] | ModelPopulateOptions;
[key: string]: any;
}): Promise<T | null> {
const { option, populates } = options;
const docsQuery = this._model.findOne(conditions, projection, option);
const { option, populates } = options || { option: {}, populates: [] };
const docsQuery = this._model.findOne(conditions, projection || {}, option);
return this.populates<T>(docsQuery, populates);
}

Expand Down
13 changes: 6 additions & 7 deletions src/shared/services/mail.services.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Injectable } from '@nestjs/common';
import { InjectMailer, MailerService } from 'core/mailer';
import { MailerService } from 'core/mailer';
import { ConfigService, EnvConfig } from 'config';
import { InjectConfig } from 'config/config.decorators';

@Injectable()
export class MailService {
private readonly from: string;
private readonly name: string;
private readonly host: string;
constructor(
@InjectMailer() private readonly mailer: MailerService,
@InjectConfig() private readonly config: ConfigService<EnvConfig>,
private readonly mailer: MailerService,
private readonly configService: ConfigService<EnvConfig>,
) {
this.name = this.config.get('name');
this.host = `${this.config.get('HOST')}:${this.config.get('PORT')}`;
this.from = `${this.name} <${this.config.get('MAIL_USER')}>`;
this.name = this.configService.get('name');
this.host = `${this.configService.get('HOST')}:${this.configService.get('PORT')}`;
this.from = `${this.name} <${this.configService.get('MAIL_USER')}>`;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/tools/get-redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function getRedisConfig(config) {
const client = config.getKeys(['REDIS_HOST', 'REDIS_PORT', 'REDIS_DB', 'REDIS_PASSWORD']);
return Object.keys(client).reduce((obj, key) => {
const field = key.split('_')[1].toLocaleUpperCase();
obj[field] = key === ('REDIS_PORT' || 'REDIS_DB') ? parseInt(client[key], 10) : client[key];
return obj;
}, {});
}

0 comments on commit b49736e

Please sign in to comment.