Skip to content

Commit

Permalink
Merge pull request #26 from tonalty/added-photolink
Browse files Browse the repository at this point in the history
feat:addedphotolink
  • Loading branch information
Konstantin1996 authored Jul 12, 2024
2 parents 61c8ffa + 2027117 commit 3625681
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
42 changes: 24 additions & 18 deletions src/communities/communityUser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,33 @@ export class CommunityUserService {

async createOrUpdateCommunityUser(userId: number, chatId: number, isAdmin: boolean): Promise<CommunityUserDto> {
const communityTitle = await this.communityService.getCommunityTitle(chatId);
const result = await this.communityUserModel.findOneAndUpdate(
{ userId: userId, chatId: chatId },
{
$setOnInsert: {
userId: userId,
chatId: chatId,
communityName: communityTitle,
points: 0,
const result = await this.communityUserModel
.findOneAndUpdate(
{ userId: userId, chatId: chatId },
{
$setOnInsert: {
userId: userId,
chatId: chatId,
communityName: communityTitle,
points: 0,
},
$set: {
// $set happens if the document is found and if it's not found
isAdmin: isAdmin,
},
},
$set: {
// $set happens if the document is found and if it's not found
isAdmin: isAdmin,
{
upsert: true,
new: true,
},
},
{
upsert: true,
new: true,
},
);
)
.lean();

const community = await this.communityService.getCommunity(chatId);

this.logger.log(`Created or updated a new community user. userId: ${userId}, chatId ${chatId}`);
return new CommunityUserDto(result);

return new CommunityUserDto(Object.assign({}, { ...result, photoLink: community.photoLink }));
}

isChatMemberAdmin(chatMember: ChatMember): boolean {
Expand Down
8 changes: 7 additions & 1 deletion src/communities/dto/CommunityUserDto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { CommunityUser } from 'src/data/communityUser.entity';

export interface ExtendedCommunityUser extends CommunityUser {
photoLink?: string;
}

export class CommunityUserDto {
communityName: string;
points: number;
isAdmin: boolean;
photoLink?: string;

constructor(communityUser: CommunityUser) {
constructor(communityUser: ExtendedCommunityUser) {
this.communityName = communityUser.communityName;
this.points = communityUser.points;
this.isAdmin = communityUser.isAdmin;
this.photoLink = communityUser.photoLink;
}
}

0 comments on commit 3625681

Please sign in to comment.