Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into renewal
  • Loading branch information
kyeahxx19 committed Oct 2, 2024
2 parents 524b7e4 + 37af190 commit 9c89e90
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
53 changes: 50 additions & 3 deletions src/domain/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,36 @@ export class BlurtingService {
group.id,
no,
);
if (!questionToProcess || no > 9) return;
if (!questionToProcess || no > 9) {
console.log(
new Date().toString() +
'blurting question process exception no exceed:' +
no,
);
return;
}

if (questionToProcess.isUploaded) return;
if (questionToProcess.isUploaded) {
console.log(
new Date().toString() +
'already uploaded - no:' +
no +
' groupId:' +
group.id,
);
return;
}
const hour =
new Date().getHours() + 9 >= 24
? new Date().getHours() + 9 - 24
: new Date().getHours() + 9;
if (hour >= 1 && hour <= 8) {
const DNDEndsAt = new Date().setHours(23);
const delay = DNDEndsAt - new Date().getTime();

await this.rQ.add({ group, no: no, users }, { delay: delay });
console.log(new Date().toString() + 'Do not disturb me until 8am');
console.log(new Date().toString() + 'no:' + no + ' groupId:' + group.id);
return;
}
await this.insertQuestionToGroup(questionToProcess.question, group, no);
Expand All @@ -91,18 +110,39 @@ export class BlurtingService {
);
}),
);
console.log(
new Date().toString() +
'question uploaded - no:' +
no +
' groupId:' +
group.id,
);
await this.blurtingPreQuestionRepository.updateToUpload(
questionToProcess.id,
);
if (no === 9) return;
if (no === 9) {
console.log(new Date().toString() + 'blurting end - groupId:' + group.id);
return;
}

if (no % 3 === 0) {
console.log(new Date().toString() + 'part end - groupId:' + group.id);
const nextPartStartsAt = new Date(
group.createdAt.getTime() + (no / 3) * (3 * 60 * 60 * 1000),
);
const delay = new Date().getTime() - nextPartStartsAt.getTime();
await this.rQ.add({ group, no: no + 1, users }, { delay: delay });
console.log(
new Date().toString() +
'next part start at: ' +
nextPartStartsAt.toString() +
' - groupId:' +
group.id,
);
} else {
console.log(
new Date().toString() + 'question added: ' + ' - groupId:' + group.id,
);
await this.rQ.add(
{ group, no: no + 1, users },
{ delay: 60 * 60 * 1000 },
Expand Down Expand Up @@ -149,6 +189,13 @@ export class BlurtingService {
question: QUESTION3[rand],
});
}
console.log(
new Date().toString() + 'pre questions added, groupId:',
group.id,
);
console.log(new Date().toString() + QUESTION1);
console.log(new Date().toString() + QUESTION2);
console.log(new Date().toString() + QUESTION3);
}

async createGroup(users: number[]): Promise<void> {
Expand Down
16 changes: 15 additions & 1 deletion src/domain/hotTopic/dtos/HotTopicInfoResponse.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { ApiProperty } from '@nestjs/swagger';
import type { HotTopicAnswerEntity } from '../entities/hotTopicAnswer.entity';
import type { HotTopicQuestionEntity } from '../entities/hotTopicQuestion.entity';
import { HotTopicSumResponseDto } from './HotTopicSumResponse.dto';
import { Sex } from 'src/common/enums';
class __AnswerDto {
constructor(entity: HotTopicAnswerEntity, userId: number) {
this.likeCount = entity.likes.length;
this.liked = entity.likes.some((like) => like.userId === userId);
this.createdAt = entity.createdAt.getTime();
this.username = entity.user.userNickname;
this.userId = entity.user.id;
this.gender = entity.user.userInfo.sex;
this.id = entity.id;
this.content = entity.answer;
}
Expand All @@ -26,6 +28,8 @@ class __AnswerDto {
content: string;
@ApiProperty({ description: '작성자 id' })
userId: number;
@ApiProperty({ description: '성별 F or M' })
gender: Sex;
}
class AnswerDto {
constructor(entity: HotTopicAnswerEntity, userId: number) {
Expand All @@ -36,6 +40,7 @@ class AnswerDto {
this.userId = entity.user.id;
this.id = entity.id;
this.content = entity.answer;
this.gender = entity.user.userInfo.sex;
if (entity.childs)
this.replies = entity.childs
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
Expand All @@ -57,6 +62,8 @@ class AnswerDto {
content: string;
@ApiProperty({ description: '답글 목록', type: [__AnswerDto] })
replies: AnswerDto[];
@ApiProperty({ description: '성별 F or M' })
gender: Sex;
}

export class HotTopicInfoResponseDto extends HotTopicSumResponseDto {
Expand All @@ -79,7 +86,14 @@ export class HotTopicInfoResponseDto extends HotTopicSumResponseDto {
liked,
);
if (bestAnswerEntity) this.bestAnswerId = bestAnswerEntity.id;
this.answers = answerEntities.map((e) => new AnswerDto(e, userId));
this.answers = answerEntities
.filter(
(e) =>
!answerEntities.find((answer) =>
answer.childs.find((child) => child.id === e.id),
),
)
.map((e) => new AnswerDto(e, userId));
}
@ApiProperty({ description: '베스트 댓글 id' })
bestAnswerId: number;
Expand Down
10 changes: 9 additions & 1 deletion src/domain/hotTopic/hotTopic.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ export class HotTopicRepository {
questionId: id,
parentId: null,
},
relations: ['likes', 'user', 'childs', 'childs.likes', 'childs.user'],
relations: [
'likes',
'user',
'user.userInfo',
'childs',
'childs.likes',
'childs.user',
'childs.user.userInfo',
],
});
const likes = await this.hotTopicLikeRepository.count({
where: { hotTopicId: id },
Expand Down
2 changes: 1 addition & 1 deletion src/domain/validation/validation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ValidationController {
@Get('/admob')
@ValidationDocs('admobValidation')
async admobValidation(@Req() req: Request) {

console.log('admob:' + req.url);
this.validationService.validateAdMob(req.url);
}

Expand Down

0 comments on commit 9c89e90

Please sign in to comment.