Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into renewal
  • Loading branch information
kyeahxx19 committed Sep 7, 2024
2 parents 8e6d01f + 5eabbcb commit 67b43af
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/domain/blurting/blurting.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import {
NotificationRepository,
ReportRepository,
} from 'src/domain/repositories';
import { BlurtingRConsumer } from './blurtingGroup.consumer';

@Module({
imports: [
UserModule,
TypeOrmModule.forFeature([
BlurtingGroupEntity,

BlurtingQuestionEntity,
BlurtingAnswerEntity,
BlurtingArrowEntity,
Expand Down Expand Up @@ -96,6 +98,7 @@ import {
BlurtingArrowRepository,
BlurtingGroupRepository,
BlurtingPreQuestionRepository,
BlurtingRConsumer,
BlurtingQuestionRepository,
BlurtingReplyRepository,
BlurtingLikeRepository,
Expand Down
23 changes: 8 additions & 15 deletions src/domain/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export class BlurtingService {
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 });
return;
}
// 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 });
// return;
// }
await this.insertQuestionToGroup(questionToProcess.question, group, no);
await Promise.all(
users.map(async (userid) => {
Expand All @@ -101,12 +101,12 @@ export class BlurtingService {
const nextPartStartsAt = new Date(
group.createdAt.getTime() + (no / 3) * (3 * 60 * 60 * 1000),
);
const delay = new Date().getTime() - nextPartStartsAt.getTime();
const delay = 30000; // new Date().getTime() - nextPartStartsAt.getTime();
await this.rQ.add({ group, no: no + 1, users }, { delay: delay });
} else {
await this.rQ.add(
{ group, no: no + 1, users },
{ delay: 60 * 60 * 1000 },
{ delay: 30000 }, //5 }, //60 * 60 * 1000 },
);
}
}
Expand All @@ -123,7 +123,6 @@ export class BlurtingService {
no: i + 1,
question: QUESTION1[rand],
});
// selected1.push(q);
}

const selected2: BlurtingPreQuestionEntity[] = [];
Expand All @@ -137,7 +136,6 @@ export class BlurtingService {
no: i + 4,
question: QUESTION2[rand],
});
// selected2.push(q);
}

const selected3: BlurtingPreQuestionEntity[] = [];
Expand All @@ -151,12 +149,7 @@ export class BlurtingService {
no: i + 7,
question: QUESTION3[rand],
});
// selected3.push(q);
}

// await this.blurtingPreQuestionRepository.save(selected1);
// await this.blurtingPreQuestionRepository.save(selected2);
// await this.blurtingPreQuestionRepository.save(selected3);
}

async createGroup(users: number[]): Promise<void> {
Expand Down
10 changes: 7 additions & 3 deletions src/domain/blurting/blurtingGroup.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export class BlurtingRConsumer {
@InjectQueue('renewaledBlurting') private readonly queue: Queue,
) {}
@Process()
async processNewBlurtingQuestion(job: Job) {
await this.blurtingService.processPreQuestions(
job.data.group,
processNewBlurtingQuestion(job: Job) {
this.blurtingService.processPreQuestions(
{
id: job.data.group.id,
createdAt: new Date(Date.parse(job.data.group.createdAt)),
questions: [],
},
job.data.no,
job.data.users,
);
Expand Down
2 changes: 1 addition & 1 deletion src/domain/firebase/fcm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class FcmService {

async sendPush(userId: number, body: string, type: string) {
const socketUser = await this.socketUserModel.findOne({ userId: userId });
if (socketUser.notificationToken) {
if (socketUser && socketUser.notificationToken) {
try {
await firebase.messaging().send({
notification: {
Expand Down
6 changes: 6 additions & 0 deletions src/domain/hotTopic/dtos/HotTopicInfoResponse.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class __AnswerDto {
this.username = entity.user.userNickname;
this.userId = entity.user.id;
this.id = entity.id;
this.content = entity.answer;
}
@ApiProperty({ description: '답변 id' })
id: number;
Expand All @@ -21,6 +22,8 @@ class __AnswerDto {
createdAt: number;
@ApiProperty({ description: '작성자 닉네임' })
username: string;
@ApiProperty({ description: '답글 내용' })
content: string;
@ApiProperty({ description: '작성자 id' })
userId: number;
}
Expand All @@ -32,6 +35,7 @@ class AnswerDto {
this.username = entity.user.userNickname;
this.userId = entity.user.id;
this.id = entity.id;
this.content = entity.answer;
if (entity.childs)
this.replies = entity.childs
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
Expand All @@ -49,6 +53,8 @@ class AnswerDto {
username: string;
@ApiProperty({ description: '작성자 id' })
userId: number;
@ApiProperty({ description: '댓글 내용' })
content: string;
@ApiProperty({ description: '답글 목록', type: [__AnswerDto] })
replies: AnswerDto[];
}
Expand Down
2 changes: 1 addition & 1 deletion src/domain/repositories/blurtingGroup.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class BlurtingGroupRepository {

async insert(): Promise<BlurtingGroupEntity> {
return this.groupRepository.save({
createdAt: new Date(new Date().getTime() + 9 * 60 * 60 * 1000),
createdAt: new Date(),
});
}
}
4 changes: 4 additions & 0 deletions src/domain/repositories/blurtingPreQuestion.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class BlurtingPreQuestionRepository {
private readonly preQuestionRepository: Repository<BlurtingPreQuestionEntity>,
) {}

async save(question: BlurtingPreQuestionEntity[]): Promise<void> {
await this.preQuestionRepository.save(question);
}

async findOne(
groupId: number,
no: number,
Expand Down
6 changes: 5 additions & 1 deletion src/domain/validation/validation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { AppStoreConnectTransactionEntity } from 'src/domain/entities';
import { ValidationController } from './validation.controller';
import { ValidationService } from './validation.service';
import { PointModule } from '../point/point.module';

@Module({
imports: [TypeOrmModule.forFeature([AppStoreConnectTransactionEntity])],
imports: [
TypeOrmModule.forFeature([AppStoreConnectTransactionEntity]),
PointModule,
],
controllers: [ValidationController],
providers: [ValidationService],
exports: [ValidationService],
Expand Down
6 changes: 5 additions & 1 deletion src/domain/validation/validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import jwt from 'jsonwebtoken';
import { AppStoreConnectTransactionEntity } from 'src/domain/entities';
import type { ProductPurchase } from 'src/interfaces/productPurchase';
import type { Repository } from 'typeorm';
import { PointService } from '../point/point.service';

@Injectable()
export class ValidationService {
constructor(
@InjectRepository(AppStoreConnectTransactionEntity)
private readonly appStoreConnectTransactionRepository: Repository<AppStoreConnectTransactionEntity>,
private readonly pointService: PointService,
) {}
private GOOGLE_AD_KEY_URL =
'https://gstatic.com/admob/reward/verifier-keys.json';
Expand Down Expand Up @@ -116,7 +118,9 @@ export class ValidationService {
const debug = false;
console.log('queryUrl', queryUrl);
await this.verify(queryUrl, debug);
// TODO: give reward

//TODO: give reward
await this.pointService.giveAdPoint(1);
}

async signAppStoreConnectJwt() {
Expand Down

0 comments on commit 67b43af

Please sign in to comment.