Browse Source

动态发布时间修改

wuyi 2 years ago
parent
commit
0f3c96c604
1 changed files with 13 additions and 21 deletions
  1. 13 21
      src/moments/moments.service.ts

+ 13 - 21
src/moments/moments.service.ts

@@ -1,11 +1,5 @@
 import {
-    Injectable,
-    NotFoundException,
-    HttpException,
-    HttpStatus,
-    BadRequestException,
-    InternalServerErrorException,
-    UnauthorizedException
+    Injectable
 } from '@nestjs/common'
 import { FindManyOptions, In, Repository, UpdateResult } from 'typeorm'
 import { InjectRepository } from '@nestjs/typeorm'
@@ -47,7 +41,6 @@ export class MomentsService {
                     this.delay()
                 }, 3 * 60 * 1000)
             }, 24 * 60 * 60 * 1000)
-            //24 * 60
         }, delayTime)
     }
 
@@ -172,21 +165,20 @@ export class MomentsService {
             const now = new Date();
             const delayTime = targetTime.getTime() - now.getTime();
 
+            console.log(moments.userId + '的动态将在' + delayTime / 1000 / 60 + '分后发布')
 
-            const hours = Math.floor(Math.random() * 12)
-            const minutes = Math.floor(Math.random() * 60)
-            console.log(moments.userId + '的动态将在' + hours + '小时' + minutes + '分后发布')
-
-            if (delayTime > 0) {
-                setTimeout(async () => {
-                    moments.isPush = true
-                    moments.createdAt = new Date()
-                    await this.momentsRepository.save(moments)
-                    const chatRole = await this.chatRoleRepository.findOneBy({ id: moments.userId })
-                    chatRole.dynamicNumber += 1
-                    await this.chatRoleRepository.save(chatRole)
-                }, delayTime)
+            if (delayTime < 0) {
+                delayTime == 0
             }
+            setTimeout(async () => {
+                moments.isPush = true
+                moments.createdAt = new Date()
+                await this.momentsRepository.save(moments)
+                const chatRole = await this.chatRoleRepository.findOneBy({ id: moments.userId })
+                chatRole.dynamicNumber += 1
+                await this.chatRoleRepository.save(chatRole)
+            }, delayTime)
+
         })
     }