Commit 3917fb3c authored by nanahira's avatar nanahira

random vote use find

parent 71091bba
Pipeline #2457 passed with stages
in 45 seconds
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { InjectConnection, InjectEntityManager } from '@nestjs/typeorm'; import { InjectConnection, InjectEntityManager } from '@nestjs/typeorm';
import { Connection, EntityManager, LessThan, MoreThanOrEqual } from 'typeorm'; import {
Connection,
EntityManager,
LessThan,
LessThanOrEqual,
MoreThanOrEqual,
} from 'typeorm';
import { UserInfo } from './entities/mycard/UserInfo'; import { UserInfo } from './entities/mycard/UserInfo';
import Filter from 'bad-words-chinese'; import Filter from 'bad-words-chinese';
import { ChineseDirtyWords } from './dirtyWordsChinese'; import { ChineseDirtyWords } from './dirtyWordsChinese';
...@@ -1038,16 +1044,17 @@ export class AppService { ...@@ -1038,16 +1044,17 @@ export class AppService {
async getRandomVote(userid: string) { async getRandomVote(userid: string) {
const now = moment().toDate(); const now = moment().toDate();
const allVotes = await this.mcdb const allVotes = await this.mcdb.getRepository(Votes).find({
.getRepository(Votes) status: true,
.createQueryBuilder('vote') startTime: LessThanOrEqual(now),
.where("vote.status = 't'") endTime: MoreThanOrEqual(now),
.andWhere('vote.start_time <= :now', { now }) });
.andWhere('vote.end_time >= :now', { now })
.getMany();
const votedIds = ( const votedIds = (
await this.mcdb.getRepository(VoteResult).find({ await this.mcdb.getRepository(VoteResult).find({
userid, select: ['voteId'],
where: {
userid,
},
}) })
).map((voteResult) => parseInt(voteResult.voteId)); ).map((voteResult) => parseInt(voteResult.voteId));
const validVotes = allVotes.filter((vote) => !votedIds.includes(vote.id)); const validVotes = allVotes.filter((vote) => !votedIds.includes(vote.id));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment