소스 검색

Added default data needed for registeration of the user

master
kj1352 4 년 전
부모
커밋
cbaf8917df
4개의 변경된 파일33개의 추가작업 그리고 10개의 파일을 삭제
  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 파일 보기

@@ -232,6 +232,12 @@
"@types/node": "*" "@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": { "@types/webidl-conversions": {
"version": "6.1.1", "version": "6.1.1",
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz", "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", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" "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": { "vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",


+ 5
- 3
package.json 파일 보기

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


+ 15
- 7
src/authentication/routes.ts 파일 보기

@@ -3,19 +3,26 @@ import { DB_NAME, getDatabaseClient } from '../db-utils';
import bcrypt from 'bcrypt'; import bcrypt from 'bcrypt';
import { generateJWT, SALT_ROUNDS } from './auth'; import { generateJWT, SALT_ROUNDS } from './auth';
import sendGridMail, { MailDataRequired } from '@sendgrid/mail'; 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(); 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) => { authRoutes.post('/register-applicant/', async (request, response) => {
const name: string = request.body.name; const name: string = request.body.name;
const email: string = request.body.email; const email: string = request.body.email;
const password: string = request.body.password; const password: string = request.body.password;
const userType: string = 'APPLICANT';
const isVerified: boolean = false; 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'); const userCollection = getDatabaseClient().db(DB_NAME).collection('users');
@@ -52,7 +59,8 @@ authRoutes.post('/register-applicant/', async (request, response) => {
email, email,
password: hashedPassword, password: hashedPassword,
isVerified, isVerified,
userType,
categories,
uncategorised
}); });
}); });


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


+ 2
- 0
src/models/user.ts 파일 보기

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


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

불러오는 중...
취소
저장