Skip to content

Commit

Permalink
fix db and error issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mariovyord committed Jan 8, 2024
1 parent b867fbe commit bc244fa
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 357 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ALLOW_ORIGIN="*"
ALLOW_METHODS="GET,PUT,POST,PATCH,DELETE,HEAD,OPTIONS"
ALLOW_HEADERS="Content-Type,Cache-Control,Expires"
JWT_SECRET=SUPERSECRET
DB_NAME="express_app"
DB_HOST=host.docker.internal
DB_PORT=6543
DB_USERNAME=postgres
Expand Down
10 changes: 0 additions & 10 deletions .env.local.example

This file was deleted.

11 changes: 0 additions & 11 deletions .env.test

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
depends_on:
- postgres_db
env_file:
- .env.local
- .env
volumes:
- type: bind
source: .
Expand Down
5 changes: 1 addition & 4 deletions src/config/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import dotenv from "dotenv";
/**
* Load enviroment variables
*/
if (!process.env.NODE_ENV) {
dotenv.config();
dotenv.config({ path: `.env.local`, override: true });
}
dotenv.config();

export function getConfig() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/features/article/article-entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from "../user/user-entity";

@Entity()
Expand All @@ -12,7 +12,7 @@ export class Article {
@Column({ type: "varchar", length: 2000 })
content: string;

@OneToOne(() => User)
@ManyToOne(() => User)
@JoinColumn()
owner: string;

Expand Down
8 changes: 4 additions & 4 deletions src/features/article/article-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function getOneArticle() {
data: result,
});
} catch (err) {
next(new NotFoundError(err));
next(err);
}
};
}
Expand All @@ -61,7 +61,7 @@ export function createArticle() {
data: result,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -79,7 +79,7 @@ export function updateArticle() {
data: result,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -98,7 +98,7 @@ export function deleteArticle() {
data: null,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
6 changes: 3 additions & 3 deletions src/features/comment/comment-entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from "../user/user-entity";

@Entity()
Expand All @@ -13,11 +13,11 @@ export class Comment {
@JoinColumn()
owner: string;

@OneToOne(() => Comment, { nullable: true })
@ManyToOne(() => Comment, { nullable: true })
@JoinColumn()
parent: string;

@OneToOne(() => User)
@ManyToOne(() => User)
@JoinColumn()
article: string;

Expand Down
8 changes: 4 additions & 4 deletions src/features/comment/comment-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function getOneComment() {
data: result,
});
} catch (err) {
next(new NotFoundError(err));
next(err);
}
};
}
Expand All @@ -61,7 +61,7 @@ export function createComment() {
data: result,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -79,7 +79,7 @@ export function updateComment() {
data: result,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -98,7 +98,7 @@ export function deleteComment() {
data: null,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
2 changes: 1 addition & 1 deletion src/features/user/user-entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bcrypt from "bcrypt";

import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class User {
Expand Down
12 changes: 6 additions & 6 deletions src/features/user/user-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function signUp() {
data: user,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -42,7 +42,7 @@ export function signIn() {
data: user,
});
} catch (err) {
next(new BadRequestError(err));
next(err);
}
};
}
Expand All @@ -56,7 +56,7 @@ export function signOut() {
data: null,
});
} catch (err) {
return next(new BadRequestError(err));
return next(err);
}
};
}
Expand All @@ -74,7 +74,7 @@ export function getUserData() {
data: userData,
});
} catch (err) {
return next(new BadRequestError(err));
return next(err);
}
};
}
Expand All @@ -98,7 +98,7 @@ export function updateUser() {
data: updatedUser,
});
} catch (err) {
return next(new BadRequestError(err));
return next(err);
}
};
}
Expand All @@ -123,7 +123,7 @@ export function updatePassword() {
data: updatedUser,
});
} catch (err) {
return next(new BadRequestError(err));
return next(err);
}
};
}
Empty file added tests/.gitkeep
Empty file.
71 changes: 0 additions & 71 deletions tests/article/article.test.ts

This file was deleted.

24 changes: 0 additions & 24 deletions tests/root.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions tests/setup-tests.ts

This file was deleted.

30 changes: 0 additions & 30 deletions tests/test-utils.ts

This file was deleted.

Loading

0 comments on commit bc244fa

Please sign in to comment.