Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submission for intern assesment #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_FILE_PATH=./database.sqlite
PORT = 3000
DB_HOST = localhost
DB_USER = root
DB_PASS = password101
1 change: 0 additions & 1 deletion .env-sample

This file was deleted.

40 changes: 20 additions & 20 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
Please answer the following questions.

1. What is your name?

Jaideep Singh

2. How long did you work on this project?

I worked on this project for about 90 minutes

3. What is the most challenging part of the project?

This project has been a great experience and trying to troubleshoot Sequelize sync issues has been a hurdle. Learning and fixing the database connections and also handling the edge cases was a bit challenging.

4. What did you learn from this project?

I learned a lot about working with Node.js and Express, particularly in building RESTful APIs. I also gained hands-on experience with Sequelize ORM for interacting with the SQLite database. Additionally, I became more comfortable with error handling and ensuring data integrity across various database operations.

5. What would you like to add or improve in this project?

A more realistic model would not allow public access. If I were to suggest one thing, I would consider user authentication and making the frontend of the project more welcoming and user friendly.

6. What is your feedback on this project?

I think the project was well-designed for learning basic CRUD operations using Express and Sequelize. The API functionality is solid, but I feel the project could benefit from additional features like user authentication.

7. What is your suggestion for this project?

N/A

8. Could you mark which of the following requirements you have completed?

Create a Todo App todo the following requirements:

- [ ] It should be possible to create a task.
- [ ] It should be possible to read a task.
- [ ] It should be possible to mark a task as completed.
- [ ] It should be possible to update the title of task.
- [ ] It should be possible to delete a task.
- [ ] It should be possible to list all tasks.
- [ ] It should be possible to list all completed tasks.
- [ ] It should be possible to list all pending tasks.
- [Done] It should be possible to create a task. // using the POST route makes tasks
- [Done] It should be possible to read a task. // GET route
- [Done] It should be possible to mark a task as completed. // PATCH route
- [Done] It should be possible to update the title of task. // PUT route
- [Done] It should be possible to delete a task. // DELETE route
- [Done] It should be possible to list all tasks. //GET route to pull all tasks from the database
- [Done] It should be possible to list all completed tasks. // GET route with query parameter
- [Done] It should be possible to list all pending tasks.

Once competed, you can submit a pull request to the original repository.

Ensure:

- [ ] The code is clean and readable.
- [ ] The code is well-structured.
- [ ] The code is well-commented.
- [ ] Only the required files are committed.
- [ ] Answer the questions in the pull request template.
- [Done] The code is clean and readable.
- [Done] The code is well-structured.
- [Done] The code is well-commented.
- [Done] Only the required files are committed.
- [Done] Answer the questions in the pull request template.
41 changes: 27 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
/* Author: Jaideep Singh, 11/26/2024 */

require("dotenv").config();
const express = require("express");
const sequelize = require("./database"); // Update this line
const sequelize = require("./database"); // Your database connection
const bodyParser = require("body-parser");

const app = express();
const PORT = process.env.PORT || 3000;

// Import task routes
const taskRoutes = require("./routes/tasks");

// Middleware for parsing JSON
app.use(bodyParser.json());

// Check DB connection
// Root route (to avoid "Cannot GET /")
app.get("/", (req, res) => {
res.send("Welcome to the Task Management API!");
});

// Check the database connection on startup
async function assertDatabaseConnectionOk() {
console.log(`Checking database connection...`);
try {
Expand All @@ -19,25 +28,29 @@ async function assertDatabaseConnectionOk() {
} catch (error) {
console.log("Unable to connect to the database:");
console.log(error.message);
process.exit(1);
process.exit(1); // Exit if database connection fails
}
}

assertDatabaseConnectionOk();

// Define additional models and routes here
app.use("/", taskRoutes);
// Check connection and sync database
async function startServer() {
try {
await assertDatabaseConnectionOk();

// Synchronize models with the database
sequelize
.sync({ alter: true, logging: false })
.then(() => {
// Sync database once (no need to call it twice)
await sequelize.sync({ alter: true }); // This will create or update the database structure
console.log("Database & tables created!");

// Start the server
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
})
.catch((error) => {
} catch (error) {
console.error("Failed to sync database:", error);
});
}
}

startServer();

// Define routes from taskRoutes
app.use("/tasks", taskRoutes); // Assuming taskRoutes is under /tasks
Binary file added database.sqlite
Binary file not shown.
2 changes: 2 additions & 0 deletions models/task.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Author: Jaideep Singh, 11/26/2024 */

const { Model, DataTypes } = require("sequelize");
const sequelize = require("../database");

Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/color-support

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

1 change: 1 addition & 0 deletions node_modules/.bin/mime

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

1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

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

1 change: 1 addition & 0 deletions node_modules/.bin/node-gyp

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

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

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

1 change: 1 addition & 0 deletions node_modules/.bin/nopt

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

1 change: 1 addition & 0 deletions node_modules/.bin/prebuild-install

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

1 change: 1 addition & 0 deletions node_modules/.bin/prettier

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

1 change: 1 addition & 0 deletions node_modules/.bin/rc

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

1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

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

1 change: 1 addition & 0 deletions node_modules/.bin/semver

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

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

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

Loading