server: fix get recent view

pull/60/head
fantasticit 2022-05-25 12:48:14 +08:00
parent 1e26dea10a
commit 6768ecc0e2
2 changed files with 0 additions and 23 deletions

View File

@ -9,20 +9,3 @@ export const dateFormat = (date = null, format = 'yyyy-MM-dd HH:mm:ss') => {
return dateFormatFn(t, format);
};
export const convertDateToMysqlTimestamp = (time) => {
const date = new Date(time);
return (
date.getUTCFullYear() +
'-' +
('00' + (date.getUTCMonth() + 1)).slice(-2) +
'-' +
('00' + date.getUTCDate()).slice(-2) +
' ' +
('00' + date.getUTCHours()).slice(-2) +
':' +
('00' + date.getUTCMinutes()).slice(-2) +
':' +
('00' + date.getUTCSeconds()).slice(-2)
);
};

View File

@ -1,6 +1,4 @@
import { ViewEntity } from '@entities/view.entity';
import { convertDateToMysqlTimestamp } from '@helpers/date.helper';
import { ONE_DAY } from '@helpers/log.helper';
import { parseUserAgent } from '@helpers/ua.helper';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
@ -65,9 +63,6 @@ export class ViewService {
visitedAt: Date;
}>
> {
const now = Date.now();
const from = convertDateToMysqlTimestamp(now - 3 * ONE_DAY);
const end = convertDateToMysqlTimestamp(now);
const count = 20;
const ret = await this.viewRepo.query(
@ -76,7 +71,6 @@ export class ViewService {
SELECT ANY_VALUE(documentId) as documentId, ANY_VALUE(created_at) as visitedAt
FROM view
WHERE view.userId = '${userId}'
AND (view.created_at BETWEEN '${from}' AND '${end}')
GROUP BY visitedAt
ORDER BY visitedAt DESC
) v