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
2 changes: 1 addition & 1 deletion 19-semana/futurebook/src/data/feedDataBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class FeedDB extends BaseDB implements FeedGateway{
return undefined;
};

return result[0].map((post: any) => {
return await result[0].map((post: any) => {
return new Feed(
post.id,
post.photo,
Expand Down
17 changes: 17 additions & 0 deletions 21-22-semana/futuretube/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion 21-22-semana/futuretube/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"test": "node ./node_modules/jest/bin/jest.js",
"ziplambda": "bestzip ../lambda.zip ./*",
"build": "rm -rf build && tsc",
"postbuild": "cp ./package.json build && cd build && npm i && npm run ziplambda"
"postbuild": "cp ./package.json build && cd build && yarn && npm run ziplambda"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/cors": "^2.8.6",
"@types/dotenv": "^8.2.0",
"@types/express": "4.17.2",
"@types/jest": "^24.0.25",
Expand All @@ -24,6 +25,7 @@
"@types/nodemailer": "^6.4.0",
"@types/randomstring": "^1.1.6",
"@types/uuid": "^3.4.6",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "4.17.1",
"jest": "^24.9.0",
Expand Down
13 changes: 7 additions & 6 deletions 21-22-semana/futuretube/backend/src/business/entites/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export class Feed extends Video{
description: string,
creationDate: Date,
user_id: string,
photo: string,
private name: string,
private photo: string
private userPhoto: string
){
super(id, title, link, description, creationDate, user_id)
super(id, title, link, description, creationDate, user_id, photo)
}

public getName(): string{
Expand All @@ -22,11 +23,11 @@ export class Feed extends Video{
this.name = name;
};

public getPhoto(): string{
return this.photo;
public getUserPhoto(): string{
return this.userPhoto;
}

public setPhoto(photo: string): void{
this.photo = photo;
public setUserPhoto(userPhoto: string): void{
this.userPhoto = userPhoto;
}
}
12 changes: 10 additions & 2 deletions 21-22-semana/futuretube/backend/src/business/entites/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class Video{
private link: string,
private description: string,
private creationDate: Date,
private user_id: string

private user_id: string,
private photo: string
){}

public getId(): string{
Expand Down Expand Up @@ -56,4 +56,12 @@ export class Video{
public setUser_id(user_id: string): void{
this.user_id = user_id
}

public getPhoto(): string{
return this.photo
}

public setPhoto(photo: string): void{
this.photo = photo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseError } from "./BaseError";

export class JwtMustBeProvided extends BaseError {
constructor() {
super(404, "You need a token to use this endpoint");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export interface UserGateway {
signUp(user: User): Promise<void>;
login(email: string): Promise<User | undefined>;
getAllUsers(): Promise<User[] | undefined>;
getUserById(id: string, email: string): Promise<User | undefined>;
getUserById(id: string): Promise<User | undefined>;
updatePassword(id: string, password: string): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Feed } from "../entites/feed";
export interface VideoGateway{
checkVideoByLink(link: string): Promise<Video | undefined>;
createVideo(video: Video): Promise<void>;
getVideos(orderBy: string, orderType: string, limit: number, offset: number): Promise<Feed[] | undefined>;
getVideos(): Promise<Feed[] | undefined>;
getVideoById(id: string): Promise<Feed | undefined>;
deleteVideo(id: string): Promise<void>;
updateVideo(id: string, description: string, title: string): Promise<void>;
getVideoByUser(id: string): Promise<Feed[] | undefined>;
deleteVideo(id: string, user_id: string): Promise<void>;
updateVideo(id: string, user_id: string, title: string, description: string): Promise<void>;
updateVideoTitle(id: string, user_id: string, title: string): Promise<void>;
updateVideoDescription(id: string, user_id: string, description: string): Promise<void>;
getAllUserVideos(id: string): Promise<Feed[] | undefined>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class GetAllUserUC{
name: user.getName(),
birthdate: user.getBirthdate(),
email: user.getEmail(),
type: user.getType()
type: user.getType(),
photo: user.getPhoto()
}
})
}
Expand All @@ -53,4 +54,5 @@ export interface GetAllUserUCOutputUser {
birthdate: Date;
email: string;
type: string;
photo: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { UserGateway } from "../../gateways/userGateway";
import { AuthenticationGateway } from "../../gateways/authenticationGateway";

export class GetUserDataUC {
constructor(
private userGateWay: UserGateway,
private authenticationGateway: AuthenticationGateway
){}

public async execute(input: GetUserDataUCInput): Promise<GetUserDataUCOutput>{
const userInfo = await this.authenticationGateway.getUsersInfoFromToken(input.token);

if(!userInfo){
throw new Error("User not found");
}

const user = await this.userGateWay.getUserById(userInfo.id)

if(!user){
throw new Error("User not found!")
}

return {
User: {
id: user.getId(),
name: user.getName(),
birthDate: user.getBirthdate(),
type: user.getType(),
email: user.getEmail(),
password: user.getPassword(),
photo: user.getPhoto()
}

}
}
}

export interface GetUserDataUCInput {
token: string;
}

export interface GetUserDataUCOutput{
User: GetUserDataUCOutputUser
}

export interface GetUserDataUCOutputUser{
id: string;
name: string;
birthDate: Date;
email: string;
password: string;
type: string;
photo: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class SignUpUC {
if(user){
throw new Error("This email has already been registered!")
}

const id = v4()

let type = UserType.USER
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { UserGateway } from "../../gateways/userGateway";
import { AuthenticationGateway } from "../../gateways/authenticationGateway";
import { CryptographyGateway } from "../../gateways/cryptographyGateway";
import { InvalidParameterError } from "../../error/InvalidParams";

export class UpdatePasswordUC {
constructor(
private userGateway: UserGateway,
private authenticationGateway: AuthenticationGateway,
private cryptographyGateway: CryptographyGateway
){}

public async execute(input: UpdatePasswordUCInput): Promise<UpdatePasswordUCOutput>{
const userInfo = await this.authenticationGateway.getUsersInfoFromToken(input.token)

if(!userInfo){
throw new Error("User not found!")
}

const user = await this.userGateway.getUserById(userInfo.id)

if(!user){
throw new Error("User not found!")
}

if(!input.oldPassword) {
throw new Error("You need to send the old password input!")
}

if(!input.newPassword) {
throw new Error("You need to send the new password input!")
}

const oldPassword = await this.cryptographyGateway.compare(input.oldPassword, user.getPassword());

if(!oldPassword){
throw new InvalidParameterError("Old Password is wrong!");
};

const newPassword = await this.cryptographyGateway.encrypt(input.newPassword)

await this.userGateway.updatePassword(userInfo.id, newPassword)

return {
message: "Password updated successfully!"
}
}
}

export interface UpdatePasswordUCInput{
token: string;
oldPassword: string;
newPassword: string;
}

export interface UpdatePasswordUCOutput{
message: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ export class CreateVideoUC {
throw new Error("Already have a vídeo with this link")
}

if(!input.title){
throw new Error("You need to send title input!")
}

if(!input.link){
throw new Error("You need to send link input!")
}

if(!input.description){
throw new Error("You need to send description input!")
}

if(!input.photo){
throw new Error("You need to send photo input!")
}

const id = v4();

const userInfo = this.authenticationGateway.getUsersInfoFromToken(input.token)

if(!userInfo){
throw new Error("User info are wrong")
throw new Error("User info is wrong")
}

const video = new Video(
Expand All @@ -30,7 +46,8 @@ export class CreateVideoUC {
input.link,
input.description,
new Date(),
userInfo.id
userInfo.id,
input.photo
)

await this.videoGateway.createVideo(video)
Expand All @@ -45,6 +62,7 @@ export interface CreateVideoUCInput {
title: string;
link: string;
description: string;
photo: string;
token: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export class DeleteVideoUC{
throw new Error("Video not found")
}

await this.videoGateway.deleteVideo(input.id)
if(userInfo.id !== video.getUser_id()){
throw new Error("You cannot delete this Video")
}

await this.videoGateway.deleteVideo(input.id, userInfo.id)

return {
message: `Video ${input.id} Deleted Successfully!`
Expand Down
Loading