Skip to content

Commit 107cd3a

Browse files
committed
Docker File added
1 parent 742fbc0 commit 107cd3a

File tree

7 files changed

+76
-13
lines changed

7 files changed

+76
-13
lines changed

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /usr/src/app
4+
5+
# Copy package files and install dependencies
6+
COPY package*.json ./
7+
RUN npm install
8+
9+
# Create the logs directory and set permissions
10+
RUN mkdir -p /usr/src/app/logs && chmod -R 777 /usr/src/app/logs
11+
12+
# Copy all source files
13+
COPY . .
14+
15+
# Generate Prisma Client
16+
RUN npx prisma generate
17+
18+
# Expose the application port
19+
EXPOSE ${PORT}
20+
21+
COPY entrypoint.sh /usr/src/app/entrypoint.sh
22+
RUN chmod +x /usr/src/app/entrypoint.sh
23+
24+
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
25+
26+
# Use nodemon for auto-reloading
27+
CMD ["npm", "run", "dev"]

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
`npm run build`
1616

17+
## Unit Tesing
18+
19+
`npm run test`
20+
1721

1822
## Prisma ORM
1923

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
volumes:
7+
- .:/usr/src/app
8+
- /usr/src/app/node_modules
9+
- ./src/logs:/usr/src/app/logs
10+
env_file:
11+
- ./.env
12+
ports:
13+
- "${PORT}:${PORT}"
14+
command: ["npm", "run", "dev"]
15+
environment:
16+
- NODE_ENV=development
17+
tty: true

entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Change permissions of logs directory
4+
chmod -R 777 /usr/src/app/logs
5+
6+
# Start the application
7+
exec "$@"

prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
generator client {
2-
provider = "prisma-client-js"
2+
provider = "prisma-client-js"
3+
binaryTargets = ["native", "debian-openssl-3.0.x", "linux-musl-openssl-3.0.x", "windows"]
34
}
45

56
datasource db {

src/controllers/userController.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,29 @@ export class UserController {
4040
}
4141

4242
async updateUser(req: Request, res: Response, next: NextFunction): Promise<void> {
43-
const userId = parseInt(req.params.id); // Extract user ID from request params
43+
const userId = parseInt(req.params.id);
4444
const { firstName, lastName, email, phone, password } = req.body;
45-
const hashedPassword = await bcrypt.hash(password, 10);
4645

47-
const userDataToUpdate: Partial<User> = {
48-
firstName,
49-
lastName,
50-
email,
51-
phone,
52-
password : hashedPassword,
53-
updatedAt: new Date()
54-
};
46+
try{
5547

56-
try {
48+
const hashedPassword = await bcrypt.hash(password, 10);
49+
50+
const userDataToUpdate: Partial<User> = {
51+
firstName,
52+
lastName,
53+
email,
54+
phone,
55+
password : hashedPassword,
56+
updatedAt: new Date()
57+
};
58+
5759
const updatedUser = await this.userService.updateUser(userId, userDataToUpdate);
5860
if (!updatedUser) {
5961
res.status(404).json({ message: 'User not found' });
6062
return;
6163
}
62-
res.status(200).json({ message: 'User updated successfully', result: handleUserResponse(updatedUser) });
64+
res.status(200).json({ message: 'User updated successfully', result: handleUserResponse(updatedUser) });
65+
6366
} catch (error) {
6467
next(error);
6568
}

src/services/userService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ export class UserService {
2828
}
2929

3030
async updateUser(userId: number, data: Partial<User>): Promise<User | null> {
31+
try{
3132
const updatedUser = await prisma.user.update({
3233
where: { id: userId },
3334
data: data,
3435
});
3536
return updatedUser;
37+
}catch(error){
38+
throw(error);
39+
}
3640
}
3741

3842
async deleteUser(userId: number): Promise<void> {

0 commit comments

Comments
 (0)