Skip to content

Commit

Permalink
feat: add analyze date col
Browse files Browse the repository at this point in the history
添加分析数据日期字段
  • Loading branch information
B1anker committed Oct 12, 2019
1 parent b1da2f1 commit dc978ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
host: process.env.MYSQL_HOST,
port: Number(process.env.MYSQL_PORT),
database: 'blog',
username: 'blog',
username: process.env.MYSQL_USERNAME,
password: process.env.MYSQL_PASSWORD,
entities: ['src/**/**.entity{.ts,.js}'],
synchronize: true
Expand Down
3 changes: 3 additions & 0 deletions src/modules/analyze/analyze.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ export class Visit {

@Column('text')
from: string;

@Column({ type: 'varchar', length: 10 })
date: string;
}
11 changes: 9 additions & 2 deletions src/modules/analyze/analyze.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Repository } from 'typeorm';

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import * as dayjs from 'dayjs';
import { Visit } from './analyze.entity';

export interface Archive {
Expand All @@ -23,15 +24,18 @@ export class AnalyzeService {
}

public async updatePv(from: string) {
const date = dayjs().format('YYYY-MM-DD');
let pv = await this.repository.findOne({
type: 'pv',
from
from,
date
});
if (!pv) {
pv = new Visit();
pv.type = 'pv';
pv.count = 1;
pv.from = from;
pv.date = date;
} else {
pv.count++;
}
Expand All @@ -45,15 +49,18 @@ export class AnalyzeService {
}

public async updateUv(from: string) {
const date = dayjs().format('YYYY-MM-DD');
let uv = await this.repository.findOne({
type: 'uv',
from
from,
date
});
if (!uv) {
uv = new Visit();
uv.type = 'uv';
uv.count = 1;
uv.from = from;
uv.date = date;
} else {
uv.count++;
}
Expand Down

0 comments on commit dc978ff

Please sign in to comment.