Skip to content

Commit

Permalink
Merge pull request #18 from KinanaDB/Team
Browse files Browse the repository at this point in the history
Team Controller
  • Loading branch information
Mohamed-khattab authored Feb 23, 2024
2 parents a8be67b + 6769c9f commit 34c79a7
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 111 deletions.
62 changes: 34 additions & 28 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"cookie-parser": "^1.4.6",
"dotenv": "^16.4.1",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
"jsonwebtoken": "^9.0.2",
"nodemon": "^3.0.3",
"prisma": "^5.8.1"
"prisma": "^5.9.1"
}
}
8 changes: 0 additions & 8 deletions prisma/migrations/20240207163006_uuid/migration.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ CREATE TABLE "User" (
CREATE TABLE "Team" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"token" TEXT,
"expiry" TIMESTAMP(3),

CONSTRAINT "Team_pkey" PRIMARY KEY ("id")
);
Expand All @@ -40,6 +42,7 @@ CREATE TABLE "Project" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"teamId" INTEGER NOT NULL,
"uuid" TEXT NOT NULL,

CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
);
Expand All @@ -59,6 +62,9 @@ CREATE TABLE "Database" (
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Team_token_key" ON "Team"("token");

-- AddForeignKey
ALTER TABLE "TeamMembers" ADD CONSTRAINT "TeamMembers_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

Expand Down
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ model User {
model Team {
id Int @id @default(autoincrement())
name String
token String? @unique
expiry DateTime?
members TeamMembers[]
projects Project[]
}
Expand Down
120 changes: 120 additions & 0 deletions requests.rest
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,124 @@ Content-Type: application/json

{
"teamId": 1
}


//______________________________________________________

###
// Register user

POST http://localhost:3000/register
Content-Type: application/json

{
"email": "[email protected]",
"username": "salma",
"password": "1234"
}

###
// Login user

POST http://localhost:3000/login
Content-Type: application/json

{
"email": "[email protected]",
"password": "1234"
}

###
// Create team

POST http://localhost:3000/team
Content-Type: application/json

{
"teamName": "team9"
}

###
// Add member to team

PUT http://localhost:3000/team/member
Content-Type: application/json

{
"memberEmail": "[email protected]",
"teamId": 5
}

###
// Get code of team

PUT http://localhost:3000/team/code
Content-Type: application/json

{
"teamId": 9
}


###
// Join a team

PUT http://localhost:3000/team/join
Content-Type: application/json

{
"token": "2c1ce63e"
}


###
// Update team

PUT http://localhost:3000/team
Content-Type: application/json

{
"newName": "sssss",
"teamId": 9
}

###
// Get all users of the team

GET http://localhost:3000/team/member
Content-Type: application/json

{
"teamId": 7
}

###
// List all teams of the user

GET http://localhost:3000/team
Content-Type: application/json



###
// Delete member from team

DELETE http://localhost:3000/team/member
Content-Type: application/json

{
"memberEmail": "[email protected]",
"teamId": 4
}


###
// Delete team

DELETE http://localhost:3000/team
Content-Type: application/json

{
"teamId": 8
}
10 changes: 7 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import express from "express";
import bodyParser from "body-parser";
import userRoute from "./routes/userRoute.js";
import cookieParser from "cookie-parser";
import { tokenAuth } from "./middlewares/authMiddleware.js";
import projectRoute from "./routes/projectRoute.js";
import teamRoute from "./routes/teamRoute.js";

const app = express();
const port = 3000;

app.use(express.json());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use("/", userRoute);

Expand All @@ -19,7 +18,12 @@ app.get("/", tokenAuth, (req, res) => {
});

app.use("/project", projectRoute);
app.use("/team", teamRoute);

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

app.use((err, req, res, next) => {
res.status(500).json({ message: "Internal server error" });
});
Loading

0 comments on commit 34c79a7

Please sign in to comment.