diff --git a/docs/API_LISTS.md b/docs/API_LISTS.md new file mode 100644 index 0000000..ce510c2 --- /dev/null +++ b/docs/API_LISTS.md @@ -0,0 +1,24 @@ +# EndPoint List + +1. ### _Users Endpoints_ + + * [Create a new user](user-endpoints-documentation/create-new-user) `Post /signup` + * [Signin User](user-endpoints-documentation/signin) `Post /login` + * [Refresh Token](user-endpoints-documentation/refresh-token) `Post /refresh_token` + * [githubAuthValidator](user-endpoints-documentation/github signin) `Post /github` + + +2. ### _Claim & Node Documentation_ + + * [requires a valid JWT token to be passed in the request ](Claim-&-Node-Documentation/jwtVerify) `Post /claim` + * [GET claims](Claim-&-Node-Documentation/get-claims) `GET /claim/:claimId?` + * [retrieves a list of nodes]( claim-node-documentiona/gets-node) `GET /node/:nodeId?` + + +### _DETAILS_ + +``claimPost: creates a new claim in the database using the data provided in the request body. If the request contains the necessary environment variables, it also sends the claim data to a third-party service using an HTTP POST request. Returns the created claim as a JSON response. +claimGet: retrieves a list of claims from the database, filtered by optional query parameters such as a search term or pagination limits. If a claim ID is provided in the request params, returns the single claim object with that ID. Otherwise, returns an array of claim objects and a count of the total number of claims in the database. +nodesGet: retrieves a list of nodes from the database, filtered by optional query parameters such as a search term or pagination limits. If a node ID is provided in the request params, returns the single node object with that ID and any edges connected to it. Otherwise, returns an array of node objects and a count of the total number of nodes in the database. + +`` \ No newline at end of file diff --git a/docs/Chart.md b/docs/Chart.md new file mode 100644 index 0000000..8b7047c --- /dev/null +++ b/docs/Chart.md @@ -0,0 +1,7 @@ +# TRUST_CLAIM + + +## Process Flow + +![Diagram](./flow1.png) + diff --git a/docs/flow1.png b/docs/flow1.png new file mode 100644 index 0000000..588c6ca Binary files /dev/null and b/docs/flow1.png differ diff --git a/prisma/migrations/20230406062906_postgres_init/migration.sql b/prisma/migrations/20230406062906_postgres_init/migration.sql new file mode 100644 index 0000000..fa3a4f1 --- /dev/null +++ b/prisma/migrations/20230406062906_postgres_init/migration.sql @@ -0,0 +1,93 @@ +-- CreateEnum +CREATE TYPE "AuthType" AS ENUM ('PASSWORD', 'GITHUB'); + +-- CreateEnum +CREATE TYPE "EntityType" AS ENUM ('PERSON', 'ORGANIZATION', 'CLAIM', 'IMPACT', 'EVENT', 'DOCUMENT', 'PRODUCT', 'PLACE', 'UNKNOWN', 'OTHER'); + +-- CreateEnum +CREATE TYPE "IssuerIdType" AS ENUM ('DID', 'ETH', 'PUBKEY', 'URL'); + +-- CreateEnum +CREATE TYPE "HowKnown" AS ENUM ('FIRST_HAND', 'SECOND_HAND', 'WEB_DOCUMENT', 'VERIFIED_LOGIN', 'BLOCKCHAIN', 'SIGNED_DOCUMENT', 'PHYSICAL_DOCUMENT', 'INTEGRATION', 'RESEARCH', 'OPINION', 'OTHER'); + +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "email" TEXT, + "passwordHash" TEXT, + "name" TEXT, + "authType" "AuthType" NOT NULL DEFAULT E'PASSWORD', + "authProviderId" TEXT, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Node" ( + "id" SERIAL NOT NULL, + "nodeUri" TEXT NOT NULL, + "name" TEXT NOT NULL, + "entType" "EntityType" NOT NULL, + "descrip" TEXT NOT NULL, + "image" TEXT, + "thumbnail" TEXT, + + CONSTRAINT "Node_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Edge" ( + "id" SERIAL NOT NULL, + "startNodeId" INTEGER NOT NULL, + "endNodeId" INTEGER, + "label" TEXT NOT NULL, + "thumbnail" TEXT, + "claimId" INTEGER NOT NULL, + + CONSTRAINT "Edge_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Claim" ( + "id" SERIAL NOT NULL, + "subject" TEXT NOT NULL, + "claim" TEXT NOT NULL, + "object" TEXT, + "statement" TEXT, + "effectiveDate" TIMESTAMP(3), + "sourceURI" TEXT, + "howKnown" "HowKnown", + "dateObserved" TIMESTAMP(3), + "digestMultibase" TEXT, + "author" TEXT, + "curator" TEXT, + "aspect" TEXT, + "score" DOUBLE PRECISION, + "stars" INTEGER, + "amt" DOUBLE PRECISION, + "unit" TEXT, + "howMeasured" TEXT, + "intendedAudience" TEXT, + "respondAt" TEXT, + "confidence" DOUBLE PRECISION, + "issuerId" TEXT, + "issuerIdType" "IssuerIdType", + "claimAddress" TEXT, + "proof" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastUpdatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Claim_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- AddForeignKey +ALTER TABLE "Edge" ADD CONSTRAINT "Edge_startNodeId_fkey" FOREIGN KEY ("startNodeId") REFERENCES "Node"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Edge" ADD CONSTRAINT "Edge_endNodeId_fkey" FOREIGN KEY ("endNodeId") REFERENCES "Node"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Edge" ADD CONSTRAINT "Edge_claimId_fkey" FOREIGN KEY ("claimId") REFERENCES "Claim"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/src/controllers/auth.controller.ts b/src/controllers/auth.controller.ts index bf9e60c..512f8e3 100644 --- a/src/controllers/auth.controller.ts +++ b/src/controllers/auth.controller.ts @@ -21,15 +21,26 @@ export const signup = async ( const existingUser = await prisma.user.findUnique({ where: { email } }); if (existingUser) { - throw new createError.Conflict("Email already exists"); + throw new createError.Conflict(`User with email '${email}' already exists`); + } + + if (password.length < 6) { + throw new createError.BadRequest(`Password should be at least 6 characters long`); } const passwordHash = await bcrypt.hash(password, 12); await prisma.user.create({ data: { email, passwordHash } }); - res.status(201).json({ message: "User created" }); + // res.status(201).json({ message: "User created" }); + res.status(201).json({ message: "User created successfully" }); } catch (err: any) { - passToExpressErrorHandler(err, next); + // passToExpressErrorHandler(err, next); + console.error(err); + + const message = err.message || "Internal server error"; + const status = err.status || 500; + + res.status(status).json({ message }); } };