-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
3,666 additions
and
964 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,2 @@ | ||
node_modules | ||
npm-debug.log |
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,39 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
"tab" | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"never" | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,16 @@ | ||
# 2work.shop | ||
<div align="center"> | ||
|
||
# 2workshop | ||
Freelance platform, where every client may find talents which realize their dreams. Platform use crypto-payments through smart-contract. Thats meaning only clear and straight interaction, based on trust in blockchain technology, without third parties. | ||
|
||
[2workshop.site here! Click!](http://2workshop.site/) | ||
|
||
| Part | Tech | | ||
| ------------- |:-------------: | | ||
| Server | ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white) ![Express.js](https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge&logo=express&logoColor=%2361DAFB) | | ||
| Client | ![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB) ![React Router](https://img.shields.io/badge/React_Router-CA4245?style=for-the-badge&logo=react-router&logoColor=white) | | ||
| Database | ![Postgres](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white) + knex | | ||
| Smart-contract | ![Solidity](https://img.shields.io/badge/Solidity-%23363636.svg?style=for-the-badge&logo=solidity&logoColor=white) ![Ethereum](https://img.shields.io/badge/Ethereum-3C3C3D?style=for-the-badge&logo=Ethereum&logoColor=white) | | ||
| Security and features | ![Socket.io](https://img.shields.io/badge/Socket.io-black?style=for-the-badge&logo=socket.io&badgeColor=010101) ![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white) ![JWT](https://img.shields.io/badge/JWT-black?style=for-the-badge&logo=JSON%20web%20tokens) + bcrypt | | ||
|
||
</div> |
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
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,78 @@ | ||
const jwt = require("jsonwebtoken") | ||
const config = require("config") | ||
const {validationResult} = require("express-validator") | ||
const bcrypt = require("bcrypt") | ||
const knex = require("../knex/knex") | ||
|
||
exports.register = async (req, res) => { | ||
try { | ||
console.log("auth") | ||
const errors = validationResult(req) | ||
if (!errors.isEmpty()){ | ||
return res.status(400).json({ | ||
errors: errors.array(), | ||
message: "Register error", | ||
test: req.body | ||
}) | ||
} | ||
const {email, nickname, password} = req.body | ||
console.log(req.body) | ||
const existUser = await knex("Users").where("email", email) | ||
console.log(existUser) | ||
console.log("jjj", existUser.length) | ||
if (existUser.length !== 0) { | ||
return res.status(400).json({message: "User is already exists"}) | ||
} | ||
const hashedPassword = await bcrypt.hash(password, 12) | ||
await knex("Users").insert({ email: email, nickname: nickname, password: hashedPassword }).catch(err => console.log("Transaction", err)) | ||
res.status(201).json({message: "User has been created"}) | ||
|
||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error", | ||
error: e.message | ||
}) | ||
} | ||
|
||
} | ||
|
||
exports.login = async (req, res) => { | ||
try { | ||
console.log("post on login") | ||
const errors = validationResult(req) | ||
if (!errors.isEmpty()){ | ||
return res.status(400).json({ | ||
errors: errors.array(), | ||
message: "Login error" | ||
}) | ||
} | ||
|
||
const {email, password} = req.body | ||
|
||
const user = await knex("Users").where("email", email).first() | ||
if (user == undefined || user == null) { | ||
return res.status(400).json({ | ||
message: "User doesnt exist" | ||
}) | ||
} | ||
|
||
const isMatch = await bcrypt.compare(password, user.password) | ||
|
||
if (!isMatch) { | ||
return res.status(400).json({message: "Error. Check input credentials"}) | ||
} | ||
|
||
const token = jwt.sign( | ||
{userId: user.id, roleId: user.roleId}, | ||
config.get("jwtSecret"), | ||
{expiresIn: "24h"} | ||
) | ||
res.json({token: token, userId: user.id, nickname: user.nickname, roleId: user.roleId}) | ||
|
||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error", | ||
error: e.message | ||
}) | ||
} | ||
} |
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,29 @@ | ||
const knex = require("../knex/knex") | ||
|
||
exports.getCommentsByOrderId = async (req, res) => { | ||
try { | ||
knex.raw(`SELECT * FROM "Comments" WHERE "orderId"=${req.params.order_id} `).then((comments) =>{ | ||
res.send(comments.rows) | ||
}).catch(err => console.log("Transaction", err)) | ||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error" | ||
}) | ||
} | ||
} | ||
|
||
exports.addCommentByOrderId = async (req, res) => { | ||
try { | ||
const {message} = req.body | ||
const comment_dct = { orderId: req.params.order_id, userId: req.user.userId, message: message} | ||
console.log(comment_dct) | ||
await knex("Comments").insert(comment_dct).catch(err => console.log("Transaction", err)) | ||
res.status(201).json({message: "Comment has been created"}) | ||
|
||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error {api:post:comments}", | ||
error: e.message | ||
}) | ||
} | ||
} |
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,28 @@ | ||
const knex = require("../knex/knex") | ||
|
||
exports.getMessageByChatId = async (req, res) => { | ||
try { | ||
let query = knex("ChatMessages").select("*").where("chatId", req.params.id) | ||
query.then(response => { | ||
res.send(response) | ||
}).catch(err => console.log("Transaction", err)) | ||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error" | ||
}) | ||
} | ||
} | ||
|
||
exports.addMessageByChatId = async (req, res) => { | ||
try { | ||
const {chatId, userId, message, timestamp} = req.body | ||
const message_dct = { chatId: chatId, userId: userId, message: message, timestamp: timestamp} | ||
await knex("ChatMessages").insert(message_dct).catch(err => console.log("Transaction", err)) | ||
res.status(201).json({message: "ChatMessage has been created"}) | ||
} catch (e) { | ||
res.status(500).json({ | ||
message: "Server error {api:post:comments}", | ||
error: e.message | ||
}) | ||
} | ||
} |
Oops, something went wrong.