Przeglądaj źródła

Added default data needed for registeration of the user

master
kj1352 4 lat temu
rodzic
commit
cbaf8917df
4 zmienionych plików z 33 dodań i 10 usunięć
  1. +11
    -0
      package-lock.json
  2. +5
    -3
      package.json
  3. +15
    -7
      src/authentication/routes.ts
  4. +2
    -0
      src/models/user.ts

+ 11
- 0
package-lock.json Wyświetl plik

@@ -232,6 +232,12 @@
"@types/node": "*"
}
},
"@types/uuid": {
"version": "8.3.1",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.1.tgz",
"integrity": "sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg==",
"dev": true
},
"@types/webidl-conversions": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz",
@@ -2230,6 +2236,11 @@
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
},
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",


+ 5
- 3
package.json Wyświetl plik

@@ -1,7 +1,7 @@
{
"name": "job-portal",
"name": "anamnesis",
"version": "1.0.0",
"description": "job portal backend node app",
"description": "anamnesis backend ExpressTS app",
"main": "dist/index.js",
"scripts": {
"start": "nodemon src/index.ts && tsc && node dist/src/index.js"
@@ -19,7 +19,8 @@
"mongodb": "^4.1.2",
"nodemon": "^2.0.12",
"passport": "^0.5.0",
"passport-jwt": "^4.0.0"
"passport-jwt": "^4.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
@@ -29,6 +30,7 @@
"@types/node": "^16.9.4",
"@types/passport": "^1.0.7",
"@types/passport-jwt": "^3.0.6",
"@types/uuid": "^8.3.1",
"tslint": "^6.1.3",
"typescript": "^4.4.3"
}


+ 15
- 7
src/authentication/routes.ts Wyświetl plik

@@ -3,19 +3,26 @@ import { DB_NAME, getDatabaseClient } from '../db-utils';
import bcrypt from 'bcrypt';
import { generateJWT, SALT_ROUNDS } from './auth';
import sendGridMail, { MailDataRequired } from '@sendgrid/mail';
import { Category } from '../models/category';
import { Shelf } from '..//models/shelf';
import { v4 as uuidv4 } from 'uuid';

const authRoutes = express.Router();

authRoutes.get('/users/', async (request, response) => {
response.send("List of users will be displayed");
});

authRoutes.post('/register-applicant/', async (request, response) => {
const name: string = request.body.name;
const email: string = request.body.email;
const password: string = request.body.password;
const userType: string = 'APPLICANT';
const isVerified: boolean = false;
const categories: Array<Category> = [];
const uncategorised: Shelf = {
_id: uuidv4(),
name: 'Uncategorised',
description: '',
viewType: 'PRIVATE',
isArchived: false,
addedWords: []
}

const userCollection = getDatabaseClient().db(DB_NAME).collection('users');
@@ -52,7 +59,8 @@ authRoutes.post('/register-applicant/', async (request, response) => {
email,
password: hashedPassword,
isVerified,
userType,
categories,
uncategorised
});
});

@@ -112,7 +120,7 @@ authRoutes.post('/request-verification/', async (request, response) => {
sendGridMail.send(otpMail).then(data=> {
response.send('Verification OTP sent');
return;
}, (err) => {
}, () => {
response.sendStatus(500);
response.send("SMTP system failure");
return;


+ 2
- 0
src/models/user.ts Wyświetl plik

@@ -1,4 +1,5 @@
import { Category } from "./category";
import { Shelf } from "./shelf";

export type IUser = {
_id: string,
@@ -8,4 +9,5 @@ export type IUser = {
isVerified: boolean,
otp: number,
categories: Array<Category>,
uncategorised: Shelf,
}

Ładowanie…
Anuluj
Zapisz