-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apps): fully friends microservice (#565)
- Loading branch information
Showing
20 changed files
with
949 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { FriendsBasicService } from './friends.basic.service'; | ||
import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
import { | ||
ServicesEnum, | ||
ServicePorts, | ||
} from '~/shared/constants/services.constant'; | ||
import { getEnv } from '~/shared/utils/rag-env'; | ||
import { FriendsController } from './friends.controller'; | ||
|
||
@Module({ | ||
imports: [], | ||
imports: [ | ||
ClientsModule.register([ | ||
{ | ||
name: ServicesEnum.friends, | ||
transport: Transport.TCP, | ||
options: { | ||
port: getEnv(ServicesEnum.friends)?.port || ServicePorts.friends, | ||
host: getEnv(ServicesEnum.friends)?.host || undefined, | ||
}, | ||
}, | ||
]), | ||
], | ||
controllers: [FriendsController], | ||
providers: [FriendsBasicService], | ||
exports: [FriendsBasicService], | ||
providers: [], | ||
exports: [], | ||
}) | ||
export class FriendsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { MessagePattern } from '@nestjs/microservices'; | ||
import { FriendsEvents } from '~/shared/constants/event.constant'; | ||
import { FriendsService } from './friends-service.service'; | ||
import { FriendsModel, FriendStatus } from './friends.model'; | ||
|
||
@Controller() | ||
export class FriendsServiceController { | ||
constructor(private readonly friendsService: FriendsService) {} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendsGetList }) | ||
async getFriendsList(group: string | undefined | Object) { | ||
const theGroup = group ? (group === Object ? undefined : group) : undefined; | ||
return await this.friendsService.getList(String(theGroup)); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendsGetAllByMaster }) | ||
async getAllFriends(status: FriendStatus) { | ||
return await this.friendsService.getAllByMaster(status); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendGet }) | ||
async getFriend(id: string) { | ||
return await this.friendsService.get(id); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendCreate }) | ||
async createFriend(data: { data: FriendsModel; isMaster: boolean }) { | ||
return await this.friendsService.create(data); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendUpdateByMasterOrToken }) | ||
async updateFriend(input: { | ||
id: string; | ||
data: FriendsModel; | ||
isMaster: boolean; | ||
token?: string; | ||
}) { | ||
return await this.friendsService.update( | ||
input.id, | ||
input.data, | ||
input.isMaster, | ||
input.token, | ||
); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendDeleteByMasterOrToken }) | ||
async deleteFriend(input: { id: string; isMaster: boolean; token?: string }) { | ||
return await this.friendsService.delete( | ||
input.id, | ||
input.isMaster, | ||
input.token, | ||
); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendsAnalyseFeed }) | ||
async analyseFeed() { | ||
await this.friendsService.analyseFeed(); | ||
return true; | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendAnalyseAutoCheck }) | ||
async analyseAutoCheck(id: string) { | ||
return await this.friendsService.analyseAutoCheck(id); | ||
} | ||
|
||
@MessagePattern({ cmd: FriendsEvents.FriendsCheckAlive }) | ||
async checkAlive() { | ||
return await this.friendsService.checkAliver(); | ||
} | ||
} |
Oops, something went wrong.