Skip to content

[ACC-328] move to dex validation #40

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

Merged
merged 4 commits into from
Mar 26, 2025
Merged
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
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"request": "launch",
"type": "node-terminal"
}

]
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ COINMARKET_API_KEY=<YOUR_SECRET>
```bash
docker-compose up -d
```

- This command will start a PostgreSQL instance on your local machine as defined in the docker-compose.yml file.

4. Install the dependencies:
Expand Down Expand Up @@ -125,14 +126,12 @@ A brief description of the main folders and files in the project:
- `./src/types`: TypeScript type definitions and interfaces used throughout the application.
- `./src/utils`: Utility functions and helper methods that are used across different parts of the application.


## Technologies Used

- **Next.js**: A React framework for server-side rendering, static site generation, and more.
- **PostgreSQL**: A powerful, open-source relational database system.
- **JavaScript/ES6+**: Modern JavaScript syntax and features.


## Database Setup

1. Ensure Docker is installed and running on your machine.
Expand Down
3,636 changes: 1,771 additions & 1,865 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@
"dev": "next dev -p 3001",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"lint:format": "prettier . --check --log-level warn --write \"./**/*.{js,ts,css,md,json,tsx}\""
},
"dependencies": {
"@aws-sdk/client-ses": "^3.664.0",
"@aws-sdk/client-ses": "^3.772.0",
"@aws-sdk/credential-provider-node": "^3.664.0",
"@types/jsonwebtoken": "^9.0.6",
"@types/lodash": "^4.17.0",
"@types/pg": "^8.11.5",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"axios": "^1.7.4",
"@types/jsonwebtoken": "^9.0.9",
"@types/lodash": "^4.17.16",
"@types/pg": "^8.11.11",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"axios": "^1.8.4",
"eslint-config-prettier": "^9.1.0",
"googleapis": "^134.0.0",
"jose": "^6.0.10",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"next": "14.2.18",
"next-auth": "^4.24.10",
"nodemailer": "^6.9.15",
"pg": "^8.11.5",
"react": "^18",
"react-dom": "^18",
"sequelize": "^6.37.3",
"nodemailer": "^6.10.0",
"pg": "^8.14.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sequelize": "^6.37.6",
"siwe": "^2.3.2"
},
"devDependencies": {
"@types/node": "^20.14.9",
"@types/nodemailer": "^6.4.16",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/validator": "^13.12.0",
"eslint": "^8",
"@types/node": "^20.17.27",
"@types/nodemailer": "^6.4.17",
"@types/react": "^18.3.20",
"@types/react-dom": "^18.3.5",
"@types/validator": "^13.12.2",
"eslint": "^8.57.1",
"eslint-config-next": "14.2.2",
"typescript": "^5"
"prettier": "^3.5.3",
"typescript": "^5.8.2"
}
}
15 changes: 15 additions & 0 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @type {import("prettier").Config} */
export default {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 90,
tabWidth: 2,
endOfLine: 'auto',
quoteProps: 'consistent',
bracketSpacing: true,
arrowParens: 'always',
htmlWhitespaceSensitivity: 'css',
insertPragma: false,
vueIndentScriptAndStyle: true,
};
2 changes: 2 additions & 0 deletions src/app/api/auth/exist/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export const GET = async (request: NextRequest) => {
const user = await findUserByEmailOrAddress(item);
return Response.json({
existItem: !!user,
role: user?.role,
currentWallet: user?.address,
});
};
20 changes: 7 additions & 13 deletions src/app/api/crypto/[token]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,24 @@ import { sentTokenBoughtEmail } from '@/controllers/crypto.controller';
import { TokenPurchaseTransaction } from '@/types/crypto';
import { User } from '@/models/user.model';

export const GET = async (
_: NextRequest,
{ params }: { params: { token: string } }
) => {
export const GET = async (_: NextRequest, { params }: { params: { token: string } }) => {
const { token } = params;
const client = axios.create({
baseURL: process.env.COINMARKET_API!,
});

const { data } = await client.get(
`v2/cryptocurrency/quotes/latest?symbol=${token}`,
{
headers: {
'X-CMC_PRO_API_KEY': process.env.COINMARKET_API_KEY!,
},
}
);
const { data } = await client.get(`v2/cryptocurrency/quotes/latest?symbol=${token}`, {
headers: {
'X-CMC_PRO_API_KEY': process.env.COINMARKET_API_KEY!,
},
});

return NextResponse.json(data);
};

export const POST = async (
request: NextRequest,
{ params }: { params: { token: string } }
{ params }: { params: { token: string } },
) => {
await AuthenticationMiddleware(request);

Expand Down
47 changes: 33 additions & 14 deletions src/app/api/me/complete/route.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
import _ from 'lodash';
import { getToken } from 'next-auth/jwt';
import { pick } from 'lodash';

import { associateTeam } from '@/controllers/team.controller';
import { COMPANY_MODIFIABLE_FIELDS, Company } from '@/models/company.model';
import { findUserById, getCompanyAndTeam } from '@/controllers/user.controller';
import {
findUserByEmail,
getCompanyAndTeam,
updateUserById,
} from '@/controllers/user.controller';
import { finishUpUserRegistration } from '@/controllers/company.controller';
// import { fleetGeneration } from '@/controllers/lead.controller';
import { User } from '@/models/user.model';
import { User, USER_MODIFIABLE_FIELDS } from '@/models/user.model';
import { Attributes } from 'sequelize';
import { Token } from '@/types/auth';
import { fleetGeneration } from '@/controllers/lead.controller';
import { getToken } from '@/utils/auth';
import { JwtPayload } from 'jsonwebtoken';

export async function PUT(request: NextRequest) {
const token = (await getToken({ req: request })) as Token;
const { userId = '' } = token;
const token = (await getToken({ req: request })) as JwtPayload;

if (!token) {
return Response.json({ message: 'Unauthorized' }, { status: 401 });
}

const incomingData = await request.json();
const user = (await findUserByEmail(incomingData.email)) as User;

if (!user) {
return Response.json({ message: 'User not found' }, { status: 404 });
}
const incommingUser = pick(incomingData, USER_MODIFIABLE_FIELDS) as User;

const userId = user.id!;
await updateUserById(userId, incommingUser);

if (incomingData.company) {
const incomingCompany = pick(
incomingData.company,
COMPANY_MODIFIABLE_FIELDS,
) as Attributes<Company>;
const company = await finishUpUserRegistration(userId, incomingCompany);
await associateTeam(user, company);
}

const incomingCompany = _.pick(
incomingData.company,
COMPANY_MODIFIABLE_FIELDS
) as Attributes<Company>;
const user = (await findUserById(userId)) as User;
const company = await finishUpUserRegistration(userId, incomingCompany);
await associateTeam(user, company);
const userCompleteInfo = await getCompanyAndTeam(user);
fleetGeneration(userCompleteInfo);

Expand Down
21 changes: 7 additions & 14 deletions src/app/api/me/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import _ from 'lodash';

import { getToken } from 'next-auth/jwt';
import { pick } from 'lodash';

import { AuthenticationMiddleware } from '@/middlewares/authentication.middleware';
import { USER_MODIFIABLE_FIELDS, User } from '@/models/user.model';
import {
getCompanyAndTeam,
updateUserById,
} from '@/controllers/user.controller';
import {
hasMandatoryInformation,
processOAuth,
} from '@/controllers/auth.controller';
import { getCompanyAndTeam, updateUserById } from '@/controllers/user.controller';
import { hasMandatoryInformation, processOAuth } from '@/controllers/auth.controller';
import { Token } from '@/types/auth';
import { isErrorWithMessage } from '@/utils/error.utils';
import { acceptTeamInvitation } from '@/controllers/teamCollaborator.controller';
import { getToken } from '@/utils/auth';

export const GET = async (request: NextRequest) => {
try {
Expand All @@ -24,7 +17,7 @@ export const GET = async (request: NextRequest) => {
const invitationCode = request.nextUrl.searchParams.get('invitation_code');
const [user, isNew] = await processOAuth(token);
await acceptTeamInvitation(user, isNew, invitationCode).catch((error) =>
console.error(error.message)
console.error(error.message),
);
const userCompleteInfo = await getCompanyAndTeam(user);
return Response.json(userCompleteInfo);
Expand All @@ -34,7 +27,7 @@ export const GET = async (request: NextRequest) => {
{
message: message,
},
{ status: 400 }
{ status: 400 },
);
}
};
Expand All @@ -44,7 +37,7 @@ export async function PUT(request: NextRequest) {
const { id: userId = '' } = request.user!.user as User;
const incomingData = await request.json();

const incomingUser = _.pick(incomingData, USER_MODIFIABLE_FIELDS) as User;
const incomingUser = pick(incomingData, USER_MODIFIABLE_FIELDS) as User;
const user = (await updateUserById(userId, incomingUser)) as User;
return Response.json(user);
}
16 changes: 6 additions & 10 deletions src/app/api/my/apps/[id]/redirect-uris/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ import { IUserWithCompanyAndTeam } from '@/types/user';

type Params = { params: { id: string } };

export const POST = async (
request: NextRequest,
{ params: { id: appId } }: Params
) => {
export const POST = async (request: NextRequest, { params: { id: appId } }: Params) => {
try {
await AuthenticationMiddleware(request);
const loggedUser = request.user?.user as User;
const userCompleteInfo = (await getCompanyAndTeam(
loggedUser
loggedUser,
)) as IUserWithCompanyAndTeam;

const redirectUriInput = _.pick(
await request.json(),
MODIFIABLE_FIELDS
) as Partial<Attributes<RedirectUri>>;
const redirectUriInput = _.pick(await request.json(), MODIFIABLE_FIELDS) as Partial<
Attributes<RedirectUri>
>;

const createdRedirectUri = await createOwnRedirectUri(
redirectUriInput,
appId,
userCompleteInfo
userCompleteInfo,
);

return Response.json(createdRedirectUri);
Expand Down
10 changes: 2 additions & 8 deletions src/app/api/my/apps/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { updateWorkspace } from '@/controllers/workspace.controller';

type Params = { params: { id: string } };

export const GET = async (
request: NextRequest,
{ params: { id: appId } }: Params
) => {
export const GET = async (request: NextRequest, { params: { id: appId } }: Params) => {
try {
await AuthenticationMiddleware(request);

Expand All @@ -35,10 +32,7 @@ export const GET = async (
}
};

export const DELETE = async (
request: NextRequest,
{ params: { id: appId } }: Params
) => {
export const DELETE = async (request: NextRequest, { params: { id: appId } }: Params) => {
try {
await AuthenticationMiddleware(request);
const loggedUser = request.user?.user as User;
Expand Down
20 changes: 6 additions & 14 deletions src/app/api/my/apps/[id]/signers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,19 @@ import { IUserWithCompanyAndTeam } from '@/types/user';

type Params = { params: { id: string } };

export const POST = async (
request: NextRequest,
{ params: { id: appId } }: Params
) => {
export const POST = async (request: NextRequest, { params: { id: appId } }: Params) => {
try {
await AuthenticationMiddleware(request);
const loggedUser = request.user?.user as User;
const userCompleteInfo = (await getCompanyAndTeam(
loggedUser
loggedUser,
)) as IUserWithCompanyAndTeam;

const signerInput = _.pick(
await request.json(),
MODIFIABLE_FIELDS
) as Partial<Attributes<Signer>>;
const signerInput = _.pick(await request.json(), MODIFIABLE_FIELDS) as Partial<
Attributes<Signer>
>;

const createdSigner = await createOwnSigner(
signerInput,
appId,
userCompleteInfo
);
const createdSigner = await createOwnSigner(signerInput, appId, userCompleteInfo);

return Response.json(createdSigner);
} catch (error: unknown) {
Expand Down
Loading