forked from bro-students/multy-stub
Compare commits
500 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e4a7b47ab5 | |||
|
|
7066252bcb | ||
| d477a0a5f1 | |||
| 4c35decfd7 | |||
| 599170df2c | |||
| 449aef6f54 | |||
| 1d4521b803 | |||
| fa860921da | |||
|
|
2480f7c376 | ||
|
|
414383163e | ||
|
|
f856d94596 | ||
|
|
dd75c54b32 | ||
|
|
f6f9163c3f | ||
|
|
4c166a8d33 | ||
| 284be82e1e | |||
| 41b5cb6fae | |||
| c4664edd7e | |||
| 69eddf47db | |||
| 71f3f353ab | |||
| 0d1dcf21c1 | |||
| 35493a09b5 | |||
| 390d97e6d5 | |||
| eca5cba858 | |||
| 6c190b80fb | |||
| a6065dd95c | |||
| 99127c42e2 | |||
| 599ccd1582 | |||
| 2b5e5564c8 | |||
| 7937be469b | |||
| 9f72d5885e | |||
| f65fd175ca | |||
|
|
d049c29f93 | ||
|
|
351ea75072 | ||
|
|
34163788f3 | ||
|
|
4ef4dd3c1b | ||
|
|
80498a0ff0 | ||
|
|
00386cc135 | ||
|
|
f5faae7907 | ||
|
|
659f9fd684 | ||
|
|
256de78e64 | ||
|
|
1500486cd8 | ||
|
|
63a825f153 | ||
|
|
1383e360a1 | ||
|
|
ca01d1c538 | ||
|
|
a315c8d4ef | ||
|
|
5ac9559b8f | ||
|
|
7b9e7d0a99 | ||
|
|
63b25928ff | ||
|
|
7d3b563759 | ||
|
|
baba20c028 | ||
|
|
87a9b8b02d | ||
|
|
cc41fa73cd | ||
|
|
ba923b9f91 | ||
|
|
cede47157e | ||
|
|
279c4fc86d | ||
|
|
c2f8d6ecee | ||
|
|
b4858efa73 | ||
|
|
6154932d9e | ||
|
|
d4cc85f644 | ||
|
|
82e8b785c4 | ||
|
|
5785e50cc5 | ||
|
|
de101348fc | ||
|
|
f442544912 | ||
|
|
d09dbcb697 | ||
|
|
f25bae1a08 | ||
|
|
800b60fb6d | ||
|
|
36558dfb85 | ||
|
|
c11bcd5d26 | ||
|
|
8450cc2d4d | ||
|
|
b1a9ee1403 | ||
|
|
80b9d9c8c8 | ||
|
|
db6665736a | ||
|
|
81980fa011 | ||
|
|
ac5f3eee96 | ||
|
|
9d87f7479c | ||
|
|
3639524fc7 | ||
|
|
f66114b22f | ||
|
|
8090de8031 | ||
|
|
081d663711 | ||
|
|
4fe16e5aa8 | ||
|
|
1fd5495570 | ||
|
|
9d68ee735a | ||
|
|
076e51c53a | ||
|
|
409a315a25 | ||
|
|
7a3264d43d | ||
|
|
effa320fa8 | ||
|
|
cc2a66367d | ||
|
|
989b5b010e | ||
|
|
f0e7ba94d2 | ||
|
|
3739fc8449 | ||
|
|
a74d191b30 | ||
|
|
a391cc88c9 | ||
|
|
12f8e63390 | ||
|
|
37238a1385 | ||
|
|
48cd044131 | ||
|
|
5665c4bf1e | ||
|
|
ad35d47ff5 | ||
|
|
f13cdd82df | ||
|
|
d6ebe10421 | ||
|
|
6e59e801b0 | ||
|
|
5dafd60299 | ||
|
|
825d7f1dd2 | ||
|
|
a3ea53c2f0 | ||
|
|
f37f34d803 | ||
|
|
bd0b11dc4a | ||
|
|
b36106cc8c | ||
|
|
07d35c4516 | ||
|
|
471cbacb66 | ||
|
|
229b181972 | ||
|
|
72615c7b98 | ||
|
|
45cafbee91 | ||
|
|
580651094f | ||
|
|
0ee92e98b2 | ||
|
|
3d8d9ee171 | ||
|
|
bde67dc7c3 | ||
|
|
a7be793608 | ||
|
|
ca81e19d14 | ||
|
|
7bd82fedce | ||
|
|
1aeb62d490 | ||
|
|
5886270e29 | ||
|
|
8f544d5c99 | ||
|
|
8dd8ec8930 | ||
|
|
3af82f7478 | ||
|
|
39a62818e9 | ||
|
|
24ff712306 | ||
|
|
ec6b30e220 | ||
|
|
548dbfcc9d | ||
|
|
09174abaa4 | ||
|
|
7ecb73ac6e | ||
|
|
8ade320440 | ||
|
|
bffa3fa2a3 | ||
|
|
4cf29c97b9 | ||
|
|
9377771531 | ||
|
|
0a96a87f94 | ||
|
|
5c14212429 | ||
|
|
e49d38657d | ||
|
|
1c7d1fc1ae | ||
|
|
7503d076e8 | ||
|
|
04f70aaa45 | ||
|
|
7b2b7b477f | ||
|
|
da7e25d339 | ||
|
|
b9f6e4d7aa | ||
|
|
396633932b | ||
|
|
46ad6ea9f3 | ||
|
|
1fa09ecac3 | ||
|
|
18b33ae10a | ||
|
|
e4e00184a5 | ||
|
|
9177765e8c | ||
|
|
0c0c62fe1b | ||
|
|
a0c9c5bab1 | ||
|
|
01b6e4ae72 | ||
|
|
2e36ee6e8b | ||
|
|
18cfa427d2 | ||
|
|
904a227adb | ||
|
|
23e532b770 | ||
|
|
f658e1f828 | ||
|
|
0500497fc1 | ||
|
|
ea691536ac | ||
|
|
c251a640b6 | ||
|
|
8031938b2f | ||
|
|
ca4bfdade4 | ||
|
|
b5f6f6d30f | ||
|
|
36107afbc2 | ||
|
|
539b1d2277 | ||
|
|
a9490da5a6 | ||
|
|
845e57d688 | ||
|
|
6835c84cc4 | ||
|
|
337e3ee2bf | ||
|
|
72d298ef2f | ||
|
|
d410164941 | ||
|
|
6b5ae7bce1 | ||
|
|
d80c4efb49 | ||
|
|
ddcf27b022 | ||
|
|
26c53e7455 | ||
|
|
0fbbe33e8a | ||
|
|
687508d26f | ||
|
|
f89729dbeb | ||
|
|
d90fee82d5 | ||
|
|
bde6ab4c7a | ||
|
|
2d0b97be44 | ||
|
|
3c22354130 | ||
|
|
ab555cd70e | ||
|
|
95bcaf3c5e | ||
|
|
48167530fd | ||
|
|
f909d90b6f | ||
|
|
e7d114a9d9 | ||
|
|
b83e0d603c | ||
|
|
7f57b2a4d3 | ||
|
|
c8f7e47181 | ||
|
|
e5d6b7cecd | ||
|
|
8a1868482c | ||
|
|
1bf68cea08 | ||
|
|
110e8300a1 | ||
| f3566361fb | |||
| a63a229b64 | |||
| 8944508308 | |||
| 775f24cffa | |||
|
|
78b72b0edc | ||
|
|
333fe79c8b | ||
|
|
9d10c8501a | ||
|
|
d64ece382a | ||
|
|
f91f821f86 | ||
|
|
b5301f948a | ||
|
|
dd589790c2 | ||
|
|
1fcc5ed70d | ||
|
|
41dbe81001 | ||
|
|
7b685ad99e | ||
| 2f1e1dc040 | |||
|
|
70e8a6877c | ||
|
|
87fd3121f9 | ||
|
|
4f9434163e | ||
|
|
350d452a7b | ||
| 9a0669df13 | |||
|
|
c0883fc2bc | ||
| 566bce4663 | |||
| c828718498 | |||
|
|
69c280b266 | ||
| 6794b01ac8 | |||
| 1cb586f55a | |||
|
|
df21879c0d | ||
|
|
30c9c86c93 | ||
|
|
2925d0f17b | ||
|
|
752dabd015 | ||
|
|
815f11d5bc | ||
| 02eb0e60b7 | |||
| a64ac93935 | |||
| 66a48d1c7e | |||
| 26c66f16b4 | |||
| 02e50bb2f9 | |||
| fadc62c8f0 | |||
| 4759f6f7ee | |||
| 14f2164a82 | |||
| 14ef1f9bad | |||
| dc99318ff0 | |||
| d2fc5f4d5c | |||
| 938bd48fff | |||
| 96f819dc91 | |||
| 25eee8adf5 | |||
| d2b2a29d3d | |||
| 1cf71261d1 | |||
| 88552eb04f | |||
| ab92c99321 | |||
| 02963de893 | |||
| 48550416d9 | |||
| 878c5ffd68 | |||
|
|
6e37fe93f7 | ||
|
|
72a2667549 | ||
|
|
39db7b4d26 | ||
| ff25c0ecb9 | |||
|
|
f1a93bffb5 | ||
| aa231d4f43 | |||
|
|
f254d57db4 | ||
| 106f835934 | |||
| f9b30a4cfd | |||
| 5e4a99529d | |||
| 4d585002d7 | |||
| b073fe3fdf | |||
| 312cc229d8 | |||
| 11b1d670d0 | |||
|
|
522ea36bb9 | ||
|
|
8be391c8e1 | ||
|
|
ea80304c21 | ||
| 771f75ef08 | |||
|
|
edf9b2c82b | ||
|
|
8c3bf8a8ed | ||
| a88d3657bf | |||
|
|
1656ce8690 | ||
|
|
7cdbec53ee | ||
| eee00f0797 | |||
|
|
33845b743d | ||
|
|
059139e213 | ||
|
|
005e7a0ac9 | ||
| 9ee59256a9 | |||
| c2784dcf45 | |||
| 64ed9b8eda | |||
| e9814f36bf | |||
| 0bd883df59 | |||
| 1657b0c5e9 | |||
| a9673b260f | |||
|
|
8ee5ca5528 | ||
| e1e335098e | |||
| 619975d1e0 | |||
| f29bc83d56 | |||
| 61347d1aee | |||
| ac7a99ef15 | |||
| eb3f1f7e3f | |||
| 3e02ea5843 | |||
| d06aeeb246 | |||
| e331f69885 | |||
| 23f1277edb | |||
|
|
801f9ac1e3 | ||
| 16bffcafa6 | |||
| 922909397d | |||
| 233192ba01 | |||
|
|
f72d5220de | ||
|
|
30af0fb1dd | ||
| 854e249100 | |||
| eddad1cc3f | |||
| c96e435344 | |||
| 7358faef1d | |||
|
|
68de877b06 | ||
| c000106ec8 | |||
|
|
da84344a63 | ||
|
|
daf5bf7970 | ||
|
|
4ef941d62f | ||
|
|
16fda2e7ed | ||
| ff15a48414 | |||
| 367c0de6fb | |||
| 3c89d8b9a8 | |||
| bdc8d9a8e0 | |||
|
|
cbbb376fd6 | ||
|
|
faaec7c718 | ||
| 8814c2a64b | |||
| 298a82e0ae | |||
| a86eb0d4ef | |||
| 335179ad26 | |||
| a1d331b5b4 | |||
| 4b77958a92 | |||
| b36ee36e3a | |||
| 48ffee1a78 | |||
| 6e0934e585 | |||
| 846db377ef | |||
|
|
3e8a8997b9 | ||
|
|
04bce4b90f | ||
|
|
3d935af6f1 | ||
|
|
0d5dc115b6 | ||
|
|
15cfc129a5 | ||
|
|
270fe51500 | ||
|
|
8a2afc3f1b | ||
|
|
d824844ae5 | ||
|
|
f95a26acbb | ||
| e0618e431f | |||
| 1b93a8e2bb | |||
| b8dc15cbc6 | |||
|
|
949416d2a3 | ||
|
|
1ec9f1a7ec | ||
|
|
17c63e6fe0 | ||
|
|
87c1cbb19e | ||
| c86f84d037 | |||
| b8bc2c83a3 | |||
| 552457b5cb | |||
|
|
909f7e4de9 | ||
|
|
86b79a7f49 | ||
|
|
d2d8b63aba | ||
|
|
0dcf961cce | ||
|
|
38bc0c55c8 | ||
|
|
9fb4219418 | ||
|
|
fb644b6f7b | ||
|
|
d88e680413 | ||
|
|
8b7f43d15a | ||
| b9edd0091c | |||
|
|
558245f876 | ||
| a927727c1b | |||
| a9d9aa02da | |||
| e7451aea5b | |||
| 5cc580c3c5 | |||
| 3fe62ec268 | |||
| e73f7e2dc9 | |||
| 571c43c33c | |||
| 61c847b58c | |||
|
|
4d621c8bbe | ||
|
|
ab8a9ebc99 | ||
| 2d1a4ba8db | |||
| 9ed6808838 | |||
| 8bd3ccfce7 | |||
| 9818550b29 | |||
|
|
fe8a477b27 | ||
|
|
12af9b7c10 | ||
| 1871f3f96a | |||
| 05be7c4a26 | |||
|
|
46c8147172 | ||
| 271f7cab7d | |||
|
|
50e105b851 | ||
|
|
da201720c0 | ||
| b3fd86da33 | |||
| 276ef4033b | |||
|
|
a520692bc5 | ||
|
|
a327c9caeb | ||
|
|
9a8fddee3b | ||
| 149d668bea | |||
|
|
5d08c4c1c2 | ||
| 2356259823 | |||
|
|
872c921a53 | ||
| 10b5207f9a | |||
| 2ede62bcd8 | |||
| 1788f90cde | |||
| a37f7ea8a8 | |||
| 18b63bed21 | |||
| 707c3be3ec | |||
| 3d52ef9d4c | |||
| 42944af2d3 | |||
| f0f6b78cd0 | |||
|
|
7c35f17008 | ||
|
|
0208e29ae3 | ||
|
|
4d5cd104ad | ||
|
|
6702473053 | ||
| 52083097a2 | |||
| f7ac265e3b | |||
| d46841c21f | |||
| c95b015094 | |||
| 940349af29 | |||
| 268824c108 | |||
|
|
550554a7a5 | ||
| f5a8585845 | |||
| 1e67f25066 | |||
| 359a136dbf | |||
| bbc315e270 | |||
|
|
fbb5d26c8f | ||
| 9d3edcf0dd | |||
|
|
57eb548d6c | ||
|
|
34d2889c1d | ||
|
|
afc782f50f | ||
|
|
ff6e688206 | ||
|
|
4b0d9b4dbc | ||
| 2cfcd7347b | |||
| c1fe275532 | |||
| de46e9bf50 | |||
|
|
76558a7eef | ||
|
|
4bf3d662ec | ||
|
|
637939e9af | ||
|
|
02891fe301 | ||
| 6015bce32f | |||
| 528b37246b | |||
| 0c693e1bac | |||
| c77aa76645 | |||
|
|
8a0ea25029 | ||
| 6fb3f3f921 | |||
|
|
89c9d7f901 | ||
|
|
b215e22f53 | ||
|
|
f13ae33cb4 | ||
|
|
18a1095cf0 | ||
|
|
3e27c0110c | ||
| c2ada9072f | |||
| 1bd1d2b279 | |||
| 7b1ce2ae83 | |||
| de22881c28 | |||
| 20d370f120 | |||
| 85986d1844 | |||
| dccf769477 | |||
| d088ef7af8 | |||
| fad8cdfe08 | |||
| a55e6d2ab2 | |||
| eb6da8aa1b | |||
| 19a55f57c0 | |||
| b649e86a43 | |||
|
|
c53f016eec | ||
|
|
0a7cbc3434 | ||
|
|
279650db25 | ||
| 2d45b4af72 | |||
| bd4de9d7ba | |||
| 10dbe5c147 | |||
| 435f17ee22 | |||
| 677dc3dc29 | |||
| 88e3fe4172 | |||
| 21dcc8bbec | |||
| 4778dba7ed | |||
| 07a02ade1f | |||
| 311846f92d | |||
| ebd561098f | |||
| b4372eb53a | |||
| bdb6b4ca3e | |||
| 426cb70eb6 | |||
| 61441e21b8 | |||
| a6f61ba033 | |||
| 8588a7fa38 | |||
| c35185ea32 | |||
| 78a332732d | |||
| 5f54355b97 | |||
| 4efbb56905 | |||
| 50c6286190 | |||
| de29da93ba | |||
| 7cdd7e790f | |||
| 569b1b0d9e | |||
| 272961c583 | |||
| 63284d6c08 | |||
| cb56e2dd2c | |||
| 325e2f125b | |||
| 786085d4d0 | |||
| c95a00fb19 | |||
| 95373069da | |||
| b8275a4c8f | |||
| fb868bfefc | |||
| 086c94c58a | |||
| 812a95dd85 | |||
| 85ee64e92b | |||
|
|
eb87f400ee | ||
| 92cabfa048 | |||
|
|
b2a853e183 | ||
|
|
0a6d50cb60 | ||
| 7809806b83 | |||
|
|
1aa0c36c84 | ||
|
|
7c3132c54b | ||
| 8fc85a7de8 | |||
|
|
cb8b2cc5aa | ||
| 6651215eeb | |||
| 80f8cef142 | |||
|
|
5a57291523 | ||
|
|
39ab269f07 | ||
| 7cb23080bf | |||
| d74e4a8624 |
@@ -1,7 +1,7 @@
|
||||
const ObjectId = require('mongodb').ObjectID
|
||||
const getHash = require('pbkdf2-password')()
|
||||
|
||||
const { getDB } = require('../../utils/mongo')
|
||||
const { getDB } = require('../../../utils/mongo')
|
||||
|
||||
const USERS_COLLECTION = 'users'
|
||||
const LISTS_COLLECTION = 'lists'
|
||||
BIN
.bzr/legacy/bushou/images.tar
Normal file
BIN
.bzr/legacy/bushou/images.tar
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
const { getDB } = require('../../utils/mongo')
|
||||
const { getDB } = require('../../../utils/mongo')
|
||||
|
||||
let db = null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
const { getResponse } = require('../../../utils/common');
|
||||
const { getResponse } = require('../../../../utils/common');
|
||||
const {
|
||||
getTags,
|
||||
connect,
|
||||
@@ -1,7 +1,7 @@
|
||||
const { v4: uuid } = require('uuid')
|
||||
const ObjectId = require('mongodb').ObjectID
|
||||
|
||||
const { getDB } = require('../../utils/mongo')
|
||||
const { getDB } = require('../../../utils/mongo')
|
||||
const { _idToId, checkDB, _idToIdArray, filterId } = require('./utils')
|
||||
|
||||
let db = null
|
||||
36
.bzr/legacy/edateam/auth.js
Normal file
36
.bzr/legacy/edateam/auth.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const router = require('express').Router();
|
||||
const checkPassword = require('pbkdf2-password')();
|
||||
const jwt = require('jsonwebtoken');
|
||||
const {EDATEAM_JWT_TOKEN} = require('./key');
|
||||
|
||||
const {getUser, _idToId, getResponse, requiredFields, signUp} = require('./controllers');
|
||||
|
||||
router.post('/sign-in', requiredFields(['email','password']), async (req, res)=>{
|
||||
try{
|
||||
const user = await getUser(req.body);
|
||||
|
||||
checkPassword({password:req.body.password, salt:user.salt},async(err, pass, salt, hash )=>{
|
||||
if(err){
|
||||
throw new Error(err);
|
||||
}
|
||||
|
||||
if(user.password === hash){
|
||||
const {password, salt:_salt, ...rest} = user;
|
||||
const token = jwt.sign(_idToId(rest), EDATEAM_JWT_TOKEN);
|
||||
return res.send(getResponse(null, token));
|
||||
}
|
||||
return res.status(400).send(getResponse('Wrong email or password!'));
|
||||
} )
|
||||
}
|
||||
catch(error){
|
||||
res.status(400).send(getResponse(error.message));
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/sign-up', requiredFields(['email', 'login', 'password']), async (req, res) => {
|
||||
let error = null
|
||||
const data = await signUp(req.body).catch((e) => error = e.message)
|
||||
return res.status(error ? 400 : 200).send(getResponse(error, data))
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
217
.bzr/legacy/edateam/controllers.js
Normal file
217
.bzr/legacy/edateam/controllers.js
Normal file
@@ -0,0 +1,217 @@
|
||||
const ObjectId = require('mongodb').ObjectId;
|
||||
const getHash = require('pbkdf2-password')();
|
||||
const { getDB } = require('../../../utils/mongo');
|
||||
|
||||
const USERS_COLLECTION = 'users';
|
||||
const RECIPES_COLLECTION = 'recipes_collection';
|
||||
const FAVORITES_USER = 'favorites_user'
|
||||
let db =null;
|
||||
|
||||
const connect = async () => {
|
||||
db = await getDB('edateam');
|
||||
};
|
||||
|
||||
const init = async () => {
|
||||
await connect();
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
const _idToId = (data) => {
|
||||
const { _id, ...rest } = data;
|
||||
return {
|
||||
id: _id,
|
||||
...rest
|
||||
};
|
||||
}
|
||||
|
||||
const _idToArray = (data) => {
|
||||
const _idToMap = data.map((item) => _idToId(item));
|
||||
return _idToMap;
|
||||
}
|
||||
|
||||
const getResponse = (error, data, success = true) => {
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
error,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success,
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
const signUp = async ({ email, login, password }) => {
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const userCollection = db.collection(USERS_COLLECTION);
|
||||
|
||||
const userData = await userCollection.findOne({
|
||||
$or: [
|
||||
{ login },
|
||||
{ email }
|
||||
]
|
||||
})
|
||||
|
||||
if (userData?.login === login) {
|
||||
throw new Error('This login already in db!\nPlease come up with another login!');
|
||||
}
|
||||
|
||||
if (userData?.email === email) {
|
||||
throw new Error('This email already in db!\nPlease come up with another email!');
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
getHash({ password }, async (err, pass, salt, hash) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
const insertedCount = await userCollection.insertOne({ email, login, password: hash, salt });
|
||||
|
||||
if (!insertedCount) {
|
||||
return reject(new Error('Insert error!'));
|
||||
}
|
||||
resolve({});
|
||||
});
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getUser = async ({ email }) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection :((');
|
||||
}
|
||||
|
||||
try {
|
||||
const userCollection = db.collection(USERS_COLLECTION);
|
||||
const userData = await userCollection.findOne({ email });
|
||||
if (userData) {
|
||||
return userData;
|
||||
}
|
||||
throw new Error('Wrong email or password!');
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
const getListRecipes = async () => {
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const recipesCollection = db.collection(RECIPES_COLLECTION);
|
||||
const recipesData = await recipesCollection.find().toArray();
|
||||
|
||||
if (recipesData.length > 0) {
|
||||
return _idToArray(recipesData);
|
||||
} else {
|
||||
throw new Error('No recipes found in the database!');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in getListRecipes:', error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const getRecipe = async (dishId ) => {
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const recipesCollection = db.collection(RECIPES_COLLECTION);
|
||||
const id = dishId.id;
|
||||
const recipeData = await recipesCollection.findOne({ _id :new ObjectId(id) } );
|
||||
if (recipeData!=null) {
|
||||
return _idToId(recipeData);
|
||||
}
|
||||
|
||||
throw new Error('Not found recipe');
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
const addRecipe = async (recipe) => {
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const recipesCollection = db.collection(RECIPES_COLLECTION);
|
||||
const result = await recipesCollection.insertOne(recipe);
|
||||
|
||||
if (!result.insertedId) {
|
||||
throw new Error('Recipe insertion failed');
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
id: result.insertedId
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error in addRecipe:', error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const requiredFields = (fields) => (req, res, next) => {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const fieldName of fields) {
|
||||
if (!req.body[fieldName]) {
|
||||
throw new Error(`Параметр ${fieldName} не установлен`)
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
const addFavorite = async (userId, recipeId) => {
|
||||
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const favoritesCollection = db.collection(FAVORITES_USER);
|
||||
const result = await favoritesCollection.updateOne(
|
||||
{ userId: new ObjectId(userId) },
|
||||
{ $addToSet: { favorites: new ObjectId(recipeId) } },
|
||||
{ upsert: true }
|
||||
);
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new Error('Error adding favorite: ' + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const getFavorites = async (userId) => {
|
||||
try {
|
||||
db = await getDB('edateam');
|
||||
const favoritesCollection = db.collection(FAVORITES_USER);
|
||||
const userFavorites = await favoritesCollection.findOne({ userId: new ObjectId(userId) });
|
||||
|
||||
if (!userFavorites || !userFavorites.favorites || userFavorites.favorites.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const recipesCollection = db.collection(RECIPES_COLLECTION);
|
||||
const favoriteRecipes = await recipesCollection.find({ _id: { $in: userFavorites.favorites } }).toArray();
|
||||
|
||||
return favoriteRecipes;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw new Error("Failed to get user favorites with recipes");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getUser,
|
||||
signUp,
|
||||
getResponse,
|
||||
_idToId,
|
||||
_idToArray,
|
||||
getListRecipes,
|
||||
getRecipe,
|
||||
addRecipe,
|
||||
requiredFields,
|
||||
getFavorites,
|
||||
addFavorite
|
||||
};
|
||||
25
.bzr/legacy/edateam/index.js
Normal file
25
.bzr/legacy/edateam/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
router.get('/recipe-data', (request, response) => {
|
||||
response.send(require('../json/recipe-data/success.json'));
|
||||
});
|
||||
|
||||
router.get('/userpage-data', (req, res) => {
|
||||
res.send(require('../json/userpage-data/success.json'));
|
||||
});
|
||||
|
||||
router.post('/userpage-data', (req, res) => {
|
||||
res.send(require('../json/userpage-data/success.json'));
|
||||
});
|
||||
|
||||
router.get('/homepage-data', (req, res) => {
|
||||
res.send(require('../json/homepage-data/success.json'));
|
||||
});
|
||||
|
||||
router.use('/auth', require('./auth'));
|
||||
|
||||
router.use('/recipe', require('./user'));
|
||||
|
||||
router.use('/main', require('./main'));
|
||||
|
||||
module.exports = router;
|
||||
76
.bzr/legacy/edateam/json/homepage-data/success.json
Normal file
76
.bzr/legacy/edateam/json/homepage-data/success.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"src": "pancakes_meat",
|
||||
"alt": "Фотография блинчиков с мясом, сыром и луком",
|
||||
"href": "?=dish01",
|
||||
"name": "Блинчики с мясом, сыром и лучком"
|
||||
},
|
||||
{
|
||||
"src": "cheesecakes",
|
||||
"alt": "Фотография сырников из творога",
|
||||
"href": "?=dish02",
|
||||
"name": "Сырники из творога"
|
||||
},
|
||||
{
|
||||
"src": "borsch",
|
||||
"alt": "Фотография борща",
|
||||
"href": "?=dish03",
|
||||
"name": "Борщ"
|
||||
},
|
||||
{
|
||||
"src": "vareniki",
|
||||
"alt": "Фотография вареников",
|
||||
"href": "?=dish04",
|
||||
"name": "Ленивые вареники"
|
||||
},
|
||||
{
|
||||
"src": "rice_porridge",
|
||||
"alt": "Фотография рисовой каши",
|
||||
"href": "?=dish05",
|
||||
"name": "Рисовая каша"
|
||||
},
|
||||
{
|
||||
"src": "cutlets",
|
||||
"alt": "Фотография котлет по-киевски",
|
||||
"href": "?=dish06",
|
||||
"name": "Котлеты по-киевски"
|
||||
},
|
||||
{
|
||||
"src": "draniki",
|
||||
"alt": "Фотография драников",
|
||||
"href": "?=dish07",
|
||||
"name": "Драники"
|
||||
},
|
||||
{
|
||||
"src": "meringue",
|
||||
"alt": "Фотография безе",
|
||||
"href": "?=dish08",
|
||||
"name": "Безе"
|
||||
},
|
||||
{
|
||||
"src": "goulash",
|
||||
"alt": "Фотография гуляша",
|
||||
"href": "?=dish09",
|
||||
"name": "Гуляш"
|
||||
},
|
||||
{
|
||||
"src": "pancakes_cherries",
|
||||
"alt": "Фотография блинчиков с вишней и творожным сыром",
|
||||
"href": "?=dish10",
|
||||
"name": "Блинчики с вишней и творожным сыром"
|
||||
},
|
||||
{
|
||||
"src": "canned_soup",
|
||||
"alt": "Фотография супа из рыбных консервов",
|
||||
"href": "?=dish11",
|
||||
"name": "Суп из рыбных консервов"
|
||||
},
|
||||
{
|
||||
"src": "salad",
|
||||
"alt": "Фотография салата",
|
||||
"href": "?=dish12",
|
||||
"name": "Салат \"Весенний\""
|
||||
}
|
||||
]
|
||||
}
|
||||
58
.bzr/legacy/edateam/json/recipe-data/success.json
Normal file
58
.bzr/legacy/edateam/json/recipe-data/success.json
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name":"Блинчики с вишней и творожным сыром",
|
||||
|
||||
"stages":
|
||||
[
|
||||
"Смешать муку, молоко, яйца, сахар и соль в миске",
|
||||
"Добавить вишню в тесто и перемешать",
|
||||
"Вылить тесто на разогретую сковороду и обжарить с двух сторон до золотистого цвета",
|
||||
"Подавать блинчики, украсив творожным сыром сверху"
|
||||
],
|
||||
|
||||
"table":
|
||||
[
|
||||
{ "ingredient": "1",
|
||||
"weight": "500 гр",
|
||||
"price1": "500р.",
|
||||
"price2": "439р.",
|
||||
"price3": "600р." },
|
||||
|
||||
{ "ingredient": "Ингредиент 2",
|
||||
"weight": "2 шт",
|
||||
"price1": "120р.",
|
||||
"price2": "150р.",
|
||||
"price3": "130р." },
|
||||
|
||||
{ "ingredient": "Ингредиент 3",
|
||||
"weight": "500 гр",
|
||||
"price1": "12р.",
|
||||
"price2": "12.99р.",
|
||||
"price3": "10р." },
|
||||
|
||||
{ "ingredient": "Ингредиент 4",
|
||||
"weight": "500 гр",
|
||||
"price1": "500р.",
|
||||
"price2": "439р.",
|
||||
"price3": "600р." },
|
||||
|
||||
{ "ingredient": "Ингредиент 5",
|
||||
"weight": "500 гр",
|
||||
"price1": "500р.",
|
||||
"price2": "439р.",
|
||||
"price3": "600р." },
|
||||
|
||||
{ "ingredient": "Ингредиент 6",
|
||||
"weight": "500 гр",
|
||||
"price1": "500р.",
|
||||
"price2": "439р.",
|
||||
"price3": "600р." }
|
||||
],
|
||||
|
||||
"tags":
|
||||
[
|
||||
{ "name": "#блины", "href": "#01" },
|
||||
{ "name": "#вишня", "href": "#02" },
|
||||
{ "name": "#молоко"," href": "#03" }
|
||||
]
|
||||
|
||||
}
|
||||
30
.bzr/legacy/edateam/json/userpage-data/success.json
Normal file
30
.bzr/legacy/edateam/json/userpage-data/success.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"data":{
|
||||
"id":1,
|
||||
"loginname":"Логин пользователя",
|
||||
"datesignin":"2024/05/18",
|
||||
"favoritedishes":
|
||||
[
|
||||
{"id":1,
|
||||
"dishlink":"?=dish1",
|
||||
"dishname":"Блюдо1"
|
||||
},
|
||||
{"id":2,
|
||||
"dishlink":"?=dish2",
|
||||
"dishname":"Блюдо2"
|
||||
},
|
||||
{"id":3,
|
||||
"dishlink":"?=dish3",
|
||||
"dishname":"Блюдо3"
|
||||
},
|
||||
{"id":4,
|
||||
"dishlink":"?=dish4",
|
||||
"dishname":"Блюдо4"
|
||||
},
|
||||
{"id":5,
|
||||
"dishlink":"?=dish5",
|
||||
"dishname":"Блюдо5"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
3
.bzr/legacy/edateam/key.js
Normal file
3
.bzr/legacy/edateam/key.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const EDATEAM_JWT_TOKEN = 'secretyk token';
|
||||
|
||||
module.exports = {EDATEAM_JWT_TOKEN};
|
||||
51
.bzr/legacy/edateam/main.js
Normal file
51
.bzr/legacy/edateam/main.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const { getListRecipes , getRecipe, addFavorite , getFavorites} = require('./controllers');
|
||||
|
||||
const router = require('express').Router();
|
||||
|
||||
router.get('/recipes', async (req, res) => {
|
||||
try {
|
||||
const result = await getListRecipes();
|
||||
return res.status(200).json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error in GET /recipes:', error.message);
|
||||
return res.status(500).json({ success: false, message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/recipe', async(req,res)=>{
|
||||
try{
|
||||
const result = await getRecipe(req.body);
|
||||
|
||||
return res.status(200).json({success:true, data: result});
|
||||
}
|
||||
catch(error){
|
||||
console.error('Error in GET /recipes:', error.message);
|
||||
return res.status(500).json({ success: false, message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/favorites', async (req, res) => {
|
||||
try {
|
||||
|
||||
const { userId, recipeId } = req.body;
|
||||
const result = await addFavorite(userId, recipeId);
|
||||
return res.status(200).json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error in POST /favorites:', error.message);
|
||||
return res.status(500).json({ success: false, message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/get-favorites', async(req,res) =>{
|
||||
try {
|
||||
const { userId } = req.body;
|
||||
const result = await getFavorites(userId);
|
||||
console.log(result)
|
||||
return res.status(200).json({ success: true, data: result });
|
||||
} catch (error) {
|
||||
console.error('Error in POST /get-favorites:', error.message);
|
||||
return res.status(500).json({ success: false, message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
35
.bzr/legacy/edateam/user.js
Normal file
35
.bzr/legacy/edateam/user.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { requiredFields , getFavorites, addRecipe} = require('./controllers');
|
||||
|
||||
const router = require('express').Router();
|
||||
|
||||
router.post('/favorites', requiredFields('id'), async(req,res)=>{
|
||||
try{
|
||||
const recipes = await getFavorites(req.body);
|
||||
res.status(200).send(getResponse(recipes));
|
||||
}
|
||||
catch(error){
|
||||
res.status(400).send(getResponse(error.message));
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/add-recept', async (req, res) => {
|
||||
let error = null;
|
||||
let result = null;
|
||||
|
||||
try {
|
||||
result = await addRecipe(req.body);
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(`Error in POST /add-recept: ${error}`);
|
||||
}
|
||||
|
||||
return res.status(error ? 500 : 201).json({
|
||||
message: error ? error : 'Recipe added successfully',
|
||||
id: result?.id
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user