-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: signup/signin, wallet address collection and storage (#4)
* Feat: signup/signin, wallet address collection and storage * Feat: restructure entity and made corresponding changes to controller, validation, and services * feat: add check api that checks if wallet address already signed up
- Loading branch information
1 parent
dd3cb32
commit b91453b
Showing
25 changed files
with
2,109 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DB_HOST=localhost | ||
DB_PORT=5432 | ||
DB_USER=postgres | ||
DB_PASSWORD=your_password | ||
DB_NAME=skillnet | ||
JWT_SECRET=your_jwt_secret_key | ||
PORT=5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DataSource } from 'typeorm'; | ||
import User from '../entities/user.entity.js'; | ||
|
||
const AppDataSource = new DataSource({ | ||
type: 'postgres', | ||
host: process.env.DB_HOST || 'localhost', | ||
port: parseInt(process.env.DB_PORT || '5432'), | ||
username: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
synchronize: true, | ||
dropSchema: false, | ||
logging: false, | ||
entities: [User], | ||
subscribers: [], | ||
migrations: [], | ||
}); | ||
|
||
export default AppDataSource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import AuthService from '../services/auth.service.js'; | ||
import validateRegistration from '../validation/auth.validation.js'; | ||
|
||
class AuthController { | ||
constructor() { | ||
this.authService = new AuthService(); | ||
} | ||
|
||
async checkWallet(req, res) { | ||
try { | ||
const { walletAddress } = req.params; | ||
const exists = await this.authService.walletExists(walletAddress); | ||
res.json({ exists }); | ||
} catch (error) { | ||
this.handleError(res, error); | ||
} | ||
} | ||
|
||
async signup(req, res) { | ||
try { | ||
const { error } = validateRegistration(req.body); | ||
if (error) return res.status(400).json({ error: error.details[0].message }); | ||
|
||
const { user, token } = await this.authService.register(req.body); | ||
|
||
res.status(201).json({ | ||
success: true, | ||
user: { | ||
id: user.id, | ||
role: user.role, | ||
walletAddress: user.walletAddress | ||
}, | ||
token | ||
}); | ||
} catch (error) { | ||
this.handleError(res, error); | ||
} | ||
} | ||
|
||
async signin(req, res) { | ||
try { | ||
const { walletAddress } = req.body; | ||
if (!walletAddress) return res.status(400).json({ error: 'Wallet address required' }); | ||
|
||
const { user, token } = await this.authService.login(walletAddress); | ||
|
||
res.json({ | ||
success: true, | ||
user: { | ||
id: user.id, | ||
role: user.role, | ||
walletAddress: user.walletAddress | ||
}, | ||
token | ||
}); | ||
} catch (error) { | ||
this.handleError(res, error); | ||
} | ||
} | ||
|
||
handleError(res, error) { | ||
console.error('Auth Error:', error); | ||
const statusCode = error.message.includes('not found') ? 404 : | ||
error.message.includes('conflict') ? 409 : 400; | ||
res.status(statusCode).json({ | ||
success: false, | ||
error: error.message | ||
}); | ||
} | ||
} | ||
|
||
export default AuthController; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { EntitySchema } from 'typeorm'; | ||
|
||
const UserEntity = new EntitySchema({ | ||
name: 'User', | ||
tableName: 'users', | ||
columns: { | ||
id: { | ||
primary: true, | ||
type: 'int', | ||
generated: true, | ||
}, | ||
walletAddress: { | ||
type: 'varchar', | ||
unique: true, | ||
}, | ||
role: { | ||
type: 'varchar', | ||
length: 20, | ||
}, | ||
// Generalizes to job seeker/employer/institution name | ||
name: { | ||
type: 'varchar', | ||
length: 100, | ||
}, | ||
email: { | ||
type: 'varchar', | ||
unique: true, | ||
}, | ||
// Tutor-specific (nullable) | ||
title: { | ||
type: 'varchar', | ||
length: 100, | ||
nullable: true, | ||
}, | ||
// Used as bio (Job Seeker, Tutor, Institution)/description (Company) | ||
bio: { | ||
type: 'text', | ||
nullable: true, | ||
}, | ||
// Tutor-specific (nullable) | ||
skills: { | ||
type: 'simple-array', | ||
nullable: true, | ||
}, | ||
createdAt: { | ||
type: 'timestamp', | ||
createDate: true, | ||
}, | ||
}, | ||
indices: [ | ||
{ columns: ['walletAddress'] }, | ||
{ columns: ['email'] }, | ||
{ columns: ['role'] }, // Index role if querying by it frequently | ||
], | ||
}); | ||
|
||
export default UserEntity; |
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.