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

Documentations #52

Closed
wants to merge 4 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/API_LISTS.md
Original file line number Diff line number Diff line change
@@ -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.

``
7 changes: 7 additions & 0 deletions docs/Chart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TRUST_CLAIM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @romeoscript no no, every time a user makes a claim it is a raw claim

Its TOTALLY OK if its the same as someone else's claim

If they are verifying a claim they would do that by clicking on it

Please do NOT try to unique claims.



## Process Flow

![Diagram](./flow1.png)

Binary file added docs/flow1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions prisma/migrations/20230406062906_postgres_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
-- CreateEnum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this whole migration in here? We already have claims?

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;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 14 additions & 3 deletions src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
};

Expand Down