-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from toomio-official/feature/queue
Implemented the module for sqs creation
- Loading branch information
Showing
11 changed files
with
104 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
- package-ecosystem: 'npm' | ||
directory: '/' | ||
schedule: | ||
interval: "weekly" | ||
interval: 'weekly' |
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,4 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
} |
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
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,10 +1,10 @@ | ||
import { IsEmail, IsNotEmpty } from "class-validator"; | ||
import { IsEmail, IsNotEmpty } from 'class-validator'; | ||
|
||
export class UserFollowDto { | ||
@IsNotEmpty() | ||
@IsEmail() | ||
followingUserEmail: string; | ||
@IsNotEmpty() | ||
@IsEmail() | ||
followerUserEmail: string; | ||
} | ||
@IsNotEmpty() | ||
@IsEmail() | ||
followingUserEmail: string; | ||
@IsNotEmpty() | ||
@IsEmail() | ||
followerUserEmail: string; | ||
} |
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,15 +1,22 @@ | ||
import { Controller, Post, UsePipes, Put, ValidationPipe, Body } from '@nestjs/common'; | ||
import { | ||
Controller, | ||
Post, | ||
UsePipes, | ||
Put, | ||
ValidationPipe, | ||
Body, | ||
} from '@nestjs/common'; | ||
import { UsersService } from './users.service'; | ||
import { UserFollowDto } from './dto/userFollow.dto'; | ||
import { User } from './user.schema'; | ||
|
||
@Controller('/users') | ||
export class UsersController { | ||
constructor(private userService: UsersService) { } | ||
constructor(private userService: UsersService) {} | ||
|
||
@Put('/follow') | ||
@UsePipes(ValidationPipe) | ||
async FollowUser(@Body() userFollowDto: UserFollowDto): Promise<User> { | ||
return await this.userService.FollowUser(userFollowDto); | ||
} | ||
@Put('/follow') | ||
@UsePipes(ValidationPipe) | ||
async FollowUser(@Body() userFollowDto: UserFollowDto): Promise<User> { | ||
return await this.userService.FollowUser(userFollowDto); | ||
} | ||
} |
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,31 +1,41 @@ | ||
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common'; | ||
import { | ||
ConflictException, | ||
Injectable, | ||
NotFoundException, | ||
} from '@nestjs/common'; | ||
import { UserFollowDto } from './dto/userFollow.dto'; | ||
import { User } from './user.schema'; | ||
import { UserRepository } from './user.repository'; | ||
|
||
@Injectable() | ||
export class UsersService { | ||
constructor(private userRepository: UserRepository) { } | ||
constructor(private userRepository: UserRepository) {} | ||
|
||
async FollowUser(userFollowDto: UserFollowDto): Promise<User> { | ||
const followerUserEmail = userFollowDto.followerUserEmail; | ||
const followingUserEmail = userFollowDto.followingUserEmail; | ||
async FollowUser(userFollowDto: UserFollowDto): Promise<User> { | ||
const followerUserEmail = userFollowDto.followerUserEmail; | ||
const followingUserEmail = userFollowDto.followingUserEmail; | ||
|
||
const followerUser = await this.userRepository.findAUser(followerUserEmail); | ||
const followingUser = await this.userRepository.findAUser(followingUserEmail); | ||
const followerUser = await this.userRepository.findAUser(followerUserEmail); | ||
const followingUser = await this.userRepository.findAUser( | ||
followingUserEmail, | ||
); | ||
|
||
if (!followerUser) { | ||
throw new NotFoundException('Follower User Not Found'); | ||
} | ||
if (!followingUser) { | ||
throw new NotFoundException('Following User Not Found'); | ||
} | ||
if (!followerUser) { | ||
throw new NotFoundException('Follower User Not Found'); | ||
} | ||
if (!followingUser) { | ||
throw new NotFoundException('Following User Not Found'); | ||
} | ||
|
||
if (followerUser.following.find(user => user._id.toString() === followingUser._id.toString())) { | ||
throw new ConflictException('User Already Followed'); | ||
} | ||
followerUser.following.push(followingUser); | ||
return await this.userRepository.updateUser(followerUser); | ||
if ( | ||
followerUser.following.find( | ||
(user) => user._id.toString() === followingUser._id.toString(), | ||
) | ||
) { | ||
throw new ConflictException('User Already Followed'); | ||
} | ||
|
||
followerUser.following.push(followingUser); | ||
return await this.userRepository.updateUser(followerUser); | ||
} | ||
} |
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,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AwsSqsService } from './aws-sqs.service'; | ||
|
||
@Module({ | ||
providers: [AwsSqsService], | ||
}) | ||
export class AwsSqsModule {} |
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,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateQueueCommand, SQSClient } from '@aws-sdk/client-sqs'; | ||
|
||
@Injectable() | ||
export class AwsSqsService { | ||
private readonly client: SQSClient; | ||
|
||
constructor() { | ||
this.client = new SQSClient({}); | ||
} | ||
|
||
async createQueue(sqsQueueName: string) { | ||
const command = new CreateQueueCommand({ | ||
QueueName: sqsQueueName, | ||
Attributes: { | ||
DelaySeconds: '60', | ||
MessageRetentionPeriod: '86400', | ||
}, | ||
}); | ||
|
||
try { | ||
const response = await this.client.send(command); | ||
return response; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
} |
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