forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.service.ts
More file actions
40 lines (33 loc) · 1.12 KB
/
Copy pathprovider.service.ts
File metadata and controls
40 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { SplitComment } from '../split-comment.entity';
import { CreateSplitCommentDto } from '../dto/split-comment.dto';
import { MentionService } from '@/mentions/provider/service';
@Injectable()
export class SplitCommentService {
constructor(
@InjectRepository(SplitComment)
private readonly repo: Repository<SplitComment>,
private readonly mentionService: MentionService,
private readonly eventEmitter: EventEmitter2,
) {}
async createComment(userId: string, dto: CreateSplitCommentDto) {
const comment = await this.repo.save({
userId,
splitId: dto.splitId,
comment: dto.comment,
});
const mentions = this.mentionService.extractMentions(dto.comment);
if (mentions.length) {
this.eventEmitter.emit('comment.mentioned', {
splitId: dto.splitId,
mentionedUsernames: mentions,
actorId: userId,
commentId: comment.id,
});
}
return comment;
}
}