Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
608 changes: 366 additions & 242 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/jwt": "^9.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/jwt": "^10.0.1",
"@nestjs/mapped-types": "^1.2.0",
"@nestjs/mongoose": "^9.2.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/swagger": "^6.1.2",
"@nestjs/websockets": "^9.3.1",
"bcrypt": "^5.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"handlebars": "^4.7.7",
"mongoose": "^6.5.4",
"nodemailer": "^6.7.8",
Expand All @@ -47,7 +46,8 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"short-uuid": "^4.2.0"
"short-uuid": "^4.2.0",
"socket.io": "^4.5.4"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AppController', () => {

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
expect(appController.test()).toBe('Hello World!');
});
});
});
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { UserGuard } from './user.guard';
import { JwtModule } from '@nestjs/jwt';
import { SuperadminModule } from './superadmin/superadmin.module';
import { GroupModule } from './group/group.module';
import { MessageModule } from './message/message.module';
import { EventsGateway } from './message/message.gateway';
import configuration from './config/configuration';

@Module({
Expand All @@ -36,6 +38,7 @@ import configuration from './config/configuration';
AdminModule,
SuperadminModule,
GroupModule,
MessageModule,
],
controllers: [AppController],
providers: [
Expand All @@ -44,6 +47,7 @@ import configuration from './config/configuration';
useClass: UserGuard,
},
AppService,
EventsGateway,
],
})
export class AppModule {}
12 changes: 0 additions & 12 deletions src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,34 @@ import {
Param,
Delete,
} from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { ChatService } from './chat.service';
import { CreateChatDto } from './dto/create-chat.dto';
import { UpdateChatDto } from './dto/update-chat.dto';
import { Chat } from './entities/chat.entity';

@ApiTags('chat')
@Controller('chat')
export class ChatController {
constructor(private readonly chatService: ChatService) {}

@ApiOkResponse({ description: 'Created new chat.', type: Chat })
@Post()
create(@Body() createChatDto: CreateChatDto) {
return this.chatService.create(createChatDto);
}

@ApiOkResponse({
description: 'Returned all chats',
type: Chat,
isArray: true,
})
@Get()
findAll() {
return this.chatService.findAll();
}

@ApiOkResponse({ description: 'Returned chat with ID.', type: Chat })
@Get(':id')
findOne(@Param('id') id: string) {
return this.chatService.findOne(+id);
}

@ApiOkResponse({ description: 'Updated chat with ID.', type: Chat })
@Patch(':id')
update(@Param('id') id: string, @Body() updateChatDto: UpdateChatDto) {
return this.chatService.update(+id, updateChatDto);
}

@ApiOkResponse({ description: 'Deleted chat with ID.', type: Chat })
@Delete(':id')
remove(@Param('id') id: string) {
return this.chatService.remove(+id);
Expand Down
2 changes: 1 addition & 1 deletion src/group/dto/update-group.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { PartialType } from '@nestjs/mapped-types';
import { IsNotEmpty, IsString } from 'class-validator';
import { CreateGroupDto } from './create-group.dto';

Expand Down
7 changes: 6 additions & 1 deletion src/group/group.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { UserModule } from 'src/user/user.module';

@Module({
imports: [
MongooseModule.forFeature([{ name: Group.name, schema: GroupSchema }]),
MongooseModule.forFeature([
{
name: Group.name,
schema: GroupSchema,
},
]),
UserModule,
],
controllers: [GroupController],
Expand Down
6 changes: 1 addition & 5 deletions src/job/dto/create-job.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ export class CreateJobDto {

@IsString()
@IsNotEmpty()
deadline: Date;

@IsString()
@IsNotEmpty()
date_posted: Date;
deadline: string;
}
3 changes: 1 addition & 2 deletions src/job/job.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export class JobController {
job.groupId = createJobDto.groupId;
job.tags = createJobDto.tags;
job.eligibility = createJobDto.eligibility;
job.deadline = createJobDto.deadline;
job.date_posted = createJobDto.date_posted;
job.deadline = new Date(createJobDto.deadline);
job.userId = req.user._id;

return this.jobService.create(job);
Expand Down
2 changes: 2 additions & 0 deletions src/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class JobService {

create(job: Job) {
const createdJob = new this.JobModel(job);
createdJob.date_posted = new Date();

return createdJob.save();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ async function bootstrap() {
);
app.enableCors({});
await app.listen(configuration().port);

console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
18 changes: 18 additions & 0 deletions src/message/message.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EventsGateway } from './message.gateway';

describe('EventsGateway', () => {
let gateway: EventsGateway;

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

gateway = module.get<EventsGateway>(EventsGateway);
});

it('should be defined', () => {
expect(gateway).toBeDefined();
});
});
30 changes: 30 additions & 0 deletions src/message/message.gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
MessageBody,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
WsResponse,
} from '@nestjs/websockets';
import { from, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Server } from 'socket.io';

@WebSocketGateway({
cors: {
origin: '*',
},
})
export class EventsGateway {
@WebSocketServer()
server: Server;

@SubscribeMessage('events')
findAll(@MessageBody() data: any): Observable<WsResponse<number>> {
return from([1, 2, 3]).pipe(map(item => ({ event: 'events', data: item })));
}

@SubscribeMessage('identity')
async identity(@MessageBody() data: number): Promise<number> {
return data;
}
}
8 changes: 8 additions & 0 deletions src/message/message.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { EventsGateway } from './message.gateway';


@Module({})
export class MessageModule {
providers: [EventsGateway];
}
1 change: 0 additions & 1 deletion src/superadmin/entities/superadmin.entity.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/superadmin/schemas/invite-email.schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { ApiProperty } from '@nestjs/swagger';

@Schema()
export class Invite {
@Prop({ required: true })
@ApiProperty()
email: string;

@Prop({ required: true })
@ApiProperty()
invite_code: string;
}

Expand Down
18 changes: 0 additions & 18 deletions src/user/schemas/user.schema.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { ApiProperty } from '@nestjs/swagger';

export class Socials {
@ApiProperty()
facebook: string;

@ApiProperty()
instagram: string;

@ApiProperty()
linkedin: string;

@ApiProperty()
twitter: string;

@ApiProperty()
github: string;
}

Expand All @@ -38,27 +32,22 @@ export class User {
_id: string;

@Prop({ required: true })
@ApiProperty()
first_name: string;

@Prop({ required: true })
@ApiProperty()
last_name: string;

@Prop({
enum: Role,
default: Role.USER,
required: true,
})
@ApiProperty()
role: string;

@Prop({ required: true, unique: true })
@ApiProperty()
email: string;

@Prop({ required: true })
@ApiProperty()
graduation_batch: number;

@Prop({
Expand All @@ -71,31 +60,24 @@ export class User {
],
default: [],
})
@ApiProperty()
tags: string[];

@Prop({ type: Socials, required: false })
@ApiProperty()
socials: Socials;

@Prop({ required: false })
@ApiProperty()
resume: string;

@Prop({ required: false })
@ApiProperty()
bio: string;

@Prop({ required: false })
@ApiProperty()
profile_picture: string;

@Prop({ select: false, required: true })
@ApiProperty()
password: string;

@Prop({ enum: Gender, required: true })
@ApiProperty()
gender: string;
}

Expand Down
13 changes: 1 addition & 12 deletions src/utility/utility.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,32 @@ import {
import { UtilityService } from './utility.service';
import { CreateUtilityDto } from './dto/create-utility.dto';
import { UpdateUtilityDto } from './dto/update-utility.dto';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { Utility } from './entities/utility.entity';

@ApiTags('utility')
@Controller('utility')
export class UtilityController {
constructor(private readonly utilityService: UtilityService) {}
constructor(private readonly utilityService: UtilityService) { }

@ApiOkResponse({ description: 'Created new utility.', type: Utility })
@Post()
create(@Body() createUtilityDto: CreateUtilityDto) {
return this.utilityService.create(createUtilityDto);
}

@ApiOkResponse({
description: 'Returned all utilities.',
type: Utility,
isArray: true,
})
@Get()
findAll() {
return this.utilityService.findAll();
}

@ApiOkResponse({ description: 'Returned utility with ID.', type: Utility })
@Get(':id')
findOne(@Param('id') id: string) {
return this.utilityService.findOne(+id);
}

@ApiOkResponse({ description: 'Updated utility with ID.', type: Utility })
@Patch(':id')
update(@Param('id') id: string, @Body() updateUtilityDto: UpdateUtilityDto) {
return this.utilityService.update(+id, updateUtilityDto);
}

@ApiOkResponse({ description: 'Deleted utility with ID.', type: Utility })
@Delete(':id')
remove(@Param('id') id: string) {
return this.utilityService.remove(+id);
Expand Down
20 changes: 20 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const io = require('socket.io-client');

const socket = io('http://127.0.0.1:5001');
socket.on('connect', function () {
console.log('Connected');

socket.emit('events', { test: 'test' });
socket.emit('identity', 0, response =>
console.log('Identity:', response),
);
});
socket.on('events', function (data) {
console.log('event', data);
});
socket.on('exception', function (data) {
console.log('event', data);
});
socket.on('disconnect', function () {
console.log('Disconnected');
});