Skip to content

Commit

Permalink
update .
Browse files Browse the repository at this point in the history
  • Loading branch information
lambiengcode committed Apr 7, 2024
1 parent 81e0df7 commit d304a27
Show file tree
Hide file tree
Showing 26 changed files with 438 additions and 104 deletions.
Binary file modified images/waterbus-erd-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/waterbus-erd-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/core/dtos/meetings/add-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';

export class AddUserDto {
@ApiProperty()
@IsNumber()
@IsNotEmpty()
userId;
}
6 changes: 3 additions & 3 deletions src/core/dtos/meetings/leave-meeting.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';

export class LeaveMeetingDto {
@ApiProperty()
@IsNumber()
participantId: number;
// @ApiProperty()
// @IsNumber()
// participantId: number;
}
15 changes: 14 additions & 1 deletion src/core/entities/meeting.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { EntityHelper } from '../../utils/entity-helper';
import bcrypt from 'bcryptjs';
import { Participant } from './participant.entity';
import { Transform } from 'class-transformer';
import { Message } from './message.entity';
import { Member } from './member.entity';

@Entity({ name: 'meetings' })
export class Meeting extends EntityHelper {
Expand All @@ -30,11 +32,22 @@ export class Meeting extends EntityHelper {
@Column({ type: String })
password: string;

// Use for session join
@OneToMany(() => Participant, (participant) => participant.meeting, {
eager: true,
cascade: true,
})
users: Participant[];
participants: Participant[];

// Permanent access
@OneToMany(() => Member, (member) => member.meeting, {
eager: true,
cascade: true,
})
members: Member[];

@OneToMany(() => Message, (message) => message.meeting)
message: Message;

@BeforeInsert()
@BeforeUpdate()
Expand Down
49 changes: 49 additions & 0 deletions src/core/entities/member.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
DeleteDateColumn,
Column,
ManyToOne,
Index,
} from 'typeorm';
import { EntityHelper } from '../../utils/entity-helper';
import { User } from '..';
import { Meeting } from './meeting.entity';
import { MemberRole, MemberStatus } from '../enums/member';

@Entity({ name: 'members' })
export class Member extends EntityHelper {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => User, (user) => user.participant, {
eager: true,
cascade: true,
})
@Index()
user: User;

@ManyToOne(() => Meeting, (meeting) => meeting.members)
meeting: Meeting;

@Column({
type: 'enum',
enum: MemberRole,
default: MemberRole.Attendee,
})
role: MemberRole;

@Column({
type: 'enum',
enum: MemberStatus,
default: MemberStatus.Inviting,
})
status: MemberStatus;

@CreateDateColumn()
createdAt: Date;

@DeleteDateColumn()
deletedAt: Date;
}
51 changes: 51 additions & 0 deletions src/core/entities/message.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
Column,
CreateDateColumn,
DeleteDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { EntityHelper } from '../../utils/entity-helper';
import { Meeting } from './meeting.entity';
import { Status } from '../enums';
import { MessageType } from '../enums/message';

@Entity({ name: 'messages' })
export class Message extends EntityHelper {
@PrimaryGeneratedColumn()
@ApiProperty({ example: 1 })
id: number;

@ApiProperty({ example: 'Hi there!' })
@Column({ type: String })
data: string;

@ManyToOne(() => Meeting, (meeting) => meeting.participants)
meeting: Meeting;

@Column({
type: 'enum',
enum: MessageType,
default: MessageType.Default,
})
type: MessageType;

@Column({
type: 'enum',
enum: Status,
default: Status.Active,
})
status: Status;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;

@DeleteDateColumn()
deletedAt: Date;
}
11 changes: 2 additions & 9 deletions src/core/entities/participant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'typeorm';
import { EntityHelper } from '../../utils/entity-helper';
import { User } from '..';
import { ParticipantRole, Status } from '../enums';
import { Status } from '../enums';
import { Meeting } from './meeting.entity';

@Entity({ name: 'participants' })
Expand All @@ -24,16 +24,9 @@ export class Participant extends EntityHelper {
@Index()
user: User;

@ManyToOne(() => Meeting, (meeting) => meeting.users)
@ManyToOne(() => Meeting, (meeting) => meeting.participants)
meeting: Meeting;

@Column({
type: 'enum',
enum: ParticipantRole,
default: ParticipantRole.Attendee,
})
role: ParticipantRole;

@Column({
type: 'enum',
enum: Status,
Expand Down
3 changes: 3 additions & 0 deletions src/core/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class User extends EntityHelper {
@DeleteDateColumn()
deletedAt: Date;

@DeleteDateColumn()
lastSeenAt: Date;

@OneToMany(() => Participant, (participant) => participant.user)
participant: Participant;

Expand Down
1 change: 0 additions & 1 deletion src/core/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './participant-role';
export * from './status';
9 changes: 9 additions & 0 deletions src/core/enums/member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum MemberRole {
Host = 0,
Attendee = 1,
}

export enum MemberStatus {
Inviting = 0,
Joined = 1,
}
4 changes: 4 additions & 0 deletions src/core/enums/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum MessageType {
Default,
System,
}
6 changes: 0 additions & 6 deletions src/core/enums/participant-role.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/features/chats/chats.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ChatsController } from './chats.controller';

describe('ChatsController', () => {
let controller: ChatsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ChatsController],
}).compile();

controller = module.get<ChatsController>(ChatsController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
16 changes: 16 additions & 0 deletions src/features/chats/chats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ChatsUseCases } from './chats.usecase';

@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@Controller({
path: 'chats',
version: '1',
})
export class ChatsController {
constructor(
private chatsUseCases: ChatsUseCases, // private meetingFactoryService: MeetingFactoryService,
) {}
}
9 changes: 9 additions & 0 deletions src/features/chats/chats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ChatsController } from './chats.controller';
import { ChatsService } from './chats.service';

@Module({
controllers: [ChatsController],
providers: [ChatsService]
})
export class ChatsModule {}
18 changes: 18 additions & 0 deletions src/features/chats/chats.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ChatsService } from './chats.service';

describe('ChatsService', () => {
let service: ChatsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ChatsService],
}).compile();

service = module.get<ChatsService>(ChatsService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions src/features/chats/chats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class ChatsService {}
7 changes: 7 additions & 0 deletions src/features/chats/chats.usecase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Injectable } from '@nestjs/common';
import { ChatsService } from './chats.service';

@Injectable()
export class ChatsUseCases {
constructor(private chatServices: ChatsService) {}
}
5 changes: 4 additions & 1 deletion src/features/grpc/meeting-grpc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class MeetingGrpcController implements meeting.MeetingService {
const participantId = data.participantId;

try {
this.meetingsUseCases.leaveRoom(Number(roomId), Number(participantId));
this.meetingsUseCases.removeParticipant(
Number(roomId),
Number(participantId),
);

const response: meeting.LeaveRoomResponse = {
succeed: true,
Expand Down
12 changes: 9 additions & 3 deletions src/features/meetings/meetings-factory.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Injectable } from '@nestjs/common';
import { CreateMeetingDto, UpdateMeetingDto } from '../../core/dtos';
import { Meeting } from '../../core/entities/meeting.entity';
import { Participant } from 'src/core/entities/participant.entity';
import { Member } from 'src/core/entities/member.entity';

@Injectable()
export class MeetingFactoryService {
createNewRoom(room: CreateMeetingDto, participant: Participant): Meeting {
createNewRoom({
room,
member,
}: {
room: CreateMeetingDto;
member: Member;
}): Meeting {
const newRoom = new Meeting();
newRoom.title = room.title;
newRoom.password = room.password;

newRoom.users = [participant];
newRoom.members = [member];

return newRoom;
}
Expand Down
Loading

0 comments on commit d304a27

Please sign in to comment.