Compare commits

...
94 Commits
Author SHA1 Message Date
primakov bbc315e270 Merge pull request 'get count by modelname' (#38) from feature/check-jenkins into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/38
2024-10-16 11:57:57 +03:00
Primakov Alexandr Alexandrovich fbb5d26c8f get count by modelname 2024-10-16 11:55:42 +03:00
primakov 9d3edcf0dd Merge pull request 'check' (#37) from feature/check-jenkins into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/37
2024-10-16 11:38:09 +03:00
Primakov Alexandr Alexandrovich 57eb548d6c verbose 2024-10-16 11:37:47 +03:00
Primakov Alexandr Alexandrovich 34d2889c1d fix 2024-10-16 11:24:59 +03:00
Primakov Alexandr Alexandrovich afc782f50f check 2024-10-16 11:15:18 +03:00
Primakov Alexandr Alexandrovich ff6e688206 fix 2024-10-16 11:12:16 +03:00
Primakov Alexandr Alexandrovich 4b0d9b4dbc mongoose + tests 2024-10-16 11:06:23 +03:00
nekitboy1998 2cfcd7347b Merge pull request 'fix plantsRouter' (#35) from nekitboy1998-patch-1 into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/35
2024-10-15 14:43:38 +03:00
nekitboy1998 c1fe275532 fix plantsRouter 2024-10-15 14:43:06 +03:00
nekitboy1998 de46e9bf50 Merge pull request 'eecliptica' (#34) from eecliptica into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/34
2024-10-15 14:11:57 +03:00
bogap 76558a7eef remove imports 2024-10-15 14:08:47 +03:00
bogap 4bf3d662ec a 2024-10-15 13:38:49 +03:00
bogap 637939e9af corrected 2024-10-15 13:36:13 +03:00
bogap 02891fe301 corrected 2024-10-12 23:03:52 +03:00
nekitboy1998 6015bce32f Merge pull request 'Cats backend routes' (#30) from cats into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/30
2024-10-12 13:23:38 +03:00
mishablin 528b37246b Const file for token 2024-10-12 13:23:16 +03:00
mishablin 0c693e1bac Cats backend routes 2024-10-12 13:04:51 +03:00
nekitboy1998 c77aa76645 Merge pull request 'fixed a route for epja-2024-1' (#29) from enterfront into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/29
2024-10-12 12:08:41 +03:00
Nikolai Petukhov 8a0ea25029 fixed a route for epja-2024-1 2024-10-12 12:06:52 +03:00
nekitboy1998 6fb3f3f921 Merge pull request 'enterfront' (#28) from enterfront into master
Reviewed-on: https://git.bro-js.ru/bro-students/multy-stub/pulls/28
2024-10-12 11:33:43 +03:00
Nikolai Petukhov 89c9d7f901 fixed error code 2024-10-12 11:21:47 +03:00
Nikolai Petukhov b215e22f53 fixed const key, logs, deleted example 2024-10-12 11:17:21 +03:00
Nikolai Petukhov f13ae33cb4 added a route for epja-2024-1 2024-10-10 13:06:58 +03:00
Nikolai Petukhov 18a1095cf0 enterfront 2024-10-10 12:02:52 +03:00
Primakov Alexandr Alexandrovich 3e27c0110c docker compose up script fix 2024-08-23 16:38:07 +03:00
prdcsi c2ada9072f Merge pull request 'school-stage stubs' (#27) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/27
2024-06-03 23:26:56 +03:00
prdcsi 1bd1d2b279 school-stage stubs 2024-06-03 23:26:23 +03:00
prdcsi 7b1ce2ae83 Merge pull request 'school-stage stubs' (#26) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/26
2024-06-03 23:20:29 +03:00
prdcsi de22881c28 school-stage stubs 2024-06-03 23:19:56 +03:00
prdcsi 20d370f120 Merge pull request 'school-stage stubs' (#25) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/25
2024-06-03 19:02:09 +03:00
prdcsi 85986d1844 school-stage stubs 2024-06-03 19:00:44 +03:00
prdcsi dccf769477 Merge pull request 'school-stage stubs' (#24) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/24
2024-06-02 20:31:21 +03:00
prdcsi d088ef7af8 school-stage stubs 2024-06-02 20:30:51 +03:00
prdcsi fad8cdfe08 Merge pull request 'school-stage stubs' (#23) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/23
2024-06-02 20:26:27 +03:00
prdcsi a55e6d2ab2 school-stage stubs 2024-06-02 20:25:51 +03:00
prdcsi eb6da8aa1b Merge pull request 'school-stage stubs' (#22) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/22
2024-06-02 20:16:40 +03:00
prdcsi 19a55f57c0 school-stage stubs 2024-06-02 20:15:01 +03:00
guzel b649e86a43 Merge pull request 'stubs-kazan-explore' (#21) from stubs-kazan-explore into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/21
2024-06-02 15:28:00 +03:00
guzelkha c53f016eec Merge branch 'stubs-kazan-explore' of ssh://85.143.175.152:222/bro-students/multy-stub into stubs-kazan-explore 2024-06-02 15:23:45 +03:00
guzelkha 0a7cbc3434 stubs-kazan-explore change 2024-06-02 15:23:16 +03:00
Liliya Vasilova 279650db25 change stubs kazan-explore 2024-06-02 15:15:34 +03:00
Kamila 2d45b4af72 Change trip schedule stub 2024-06-02 14:15:35 +03:00
Kamila bd4de9d7ba Merge pull request 'Add trip schedule stubs kazan-explore' (#20) from stubs-kazan-explore into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/20
2024-06-02 13:20:37 +03:00
Kamila 10dbe5c147 Add trip schedule stubs kazan-explore 2024-06-02 13:18:35 +03:00
Kamila 435f17ee22 Merge pull request 'Add stubs kazan-explore' (#19) from stubs-kazan-explore into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/19
2024-06-01 20:40:27 +03:00
Kamila 677dc3dc29 Add stubs kazan-explore 2024-06-01 20:37:32 +03:00
Kamila 88e3fe4172 Merge pull request 'Add stubs kazan-explore' (#18) from stubs-kazan-explore into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/18
2024-06-01 20:34:05 +03:00
Kamila 21dcc8bbec Add stubs kazan-explore 2024-06-01 20:32:45 +03:00
Kamila 4778dba7ed Merge pull request 'stubs-kazan-explore' (#17) from stubs-kazan-explore into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/17
2024-06-01 20:25:16 +03:00
Kamila 07a02ade1f Add stubs kazan-explore 2024-06-01 20:22:43 +03:00
Kamila 311846f92d Add stubs kazan-explore 2024-06-01 19:53:28 +03:00
dqriakh ebd561098f Merge pull request 'small changes' (#16) from dhs-testing into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/16
2024-06-01 14:14:00 +03:00
dqriakh b4372eb53a small changes 2024-06-01 14:12:54 +03:00
prdcsi bdb6b4ca3e Merge pull request 'schoo;-stage stubs' (#15) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/15
2024-06-01 09:54:28 +03:00
prdcsi 426cb70eb6 schoo;-stage stubs 2024-06-01 09:53:26 +03:00
prdcsi 61441e21b8 Merge pull request 'school-stage stubs' (#14) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/14
2024-06-01 09:51:42 +03:00
prdcsi a6f61ba033 school-stage stubs 2024-06-01 09:51:14 +03:00
prdcsi 8588a7fa38 Merge pull request 'school-stage stubs' (#13) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/13
2024-06-01 00:40:16 +03:00
prdcsi c35185ea32 school-stage stubs 2024-06-01 00:39:43 +03:00
prdcsi 78a332732d Merge pull request 'api' (#12) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/12
2024-06-01 00:01:29 +03:00
prdcsi 5f54355b97 api 2024-06-01 00:00:00 +03:00
prdcsi 4efbb56905 Merge pull request 'school-stage stubs' (#10) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/10
2024-05-31 23:56:37 +03:00
dqriakh 50c6286190 Merge pull request 'edit tests data' (#11) from dhs-testing into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/11
2024-05-31 23:32:50 +03:00
dqriakh de29da93ba edit tests data 2024-05-31 23:31:21 +03:00
prdcsi 7cdd7e790f school-stage stubs 2024-05-31 22:04:23 +03:00
prdcsi 569b1b0d9e Merge pull request 'school-stage stubs' (#9) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/9
2024-05-31 18:03:52 +03:00
prdcsi 272961c583 school-stage stubs 2024-05-31 18:01:50 +03:00
prdcsi 63284d6c08 Merge pull request 'school-stage-branch' (#8) from school-stage-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/8
2024-05-31 16:49:59 +03:00
prdcsi cb56e2dd2c school-stage stubs 2024-05-31 16:38:40 +03:00
prdcsi 325e2f125b school-stage stubs 2024-05-31 16:28:05 +03:00
dqriakh 786085d4d0 Merge pull request 'dhs-testing stubs' (#7) from dhs-testing into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/7
2024-05-30 18:51:51 +03:00
dqriakh c95a00fb19 fixed json 2024-05-30 18:29:26 +03:00
dqriakh 95373069da dhs-testing stubs 2024-05-30 17:39:33 +03:00
julyashap b8275a4c8f Merge pull request 'add-dogsitters-finder' (#6) from add-dogsitters-finder into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/6
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-27 18:12:19 +03:00
julyashap fb868bfefc Change path to json 2024-05-26 16:29:12 +03:00
julyashap 086c94c58a Update json/users.json 2024-05-26 16:28:54 +03:00
primakov 812a95dd85 Merge pull request 'my-project stubs' (#4) from my into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/4
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-25 12:50:19 +03:00
primakov 85ee64e92b Merge pull request 'back add' (#5) from edateam_branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/5
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-25 12:50:05 +03:00
nothingnowhere1 eb87f400ee edit json files 2024-05-25 12:44:44 +03:00
julyashap 92cabfa048 Add dogsitters-finder to server/index.json and server/routers 2024-05-25 11:12:21 +03:00
NewPerson b2a853e183 back add 2024-05-25 00:10:46 +03:00
nothingnowhere1 0a6d50cb60 stubs 2024-05-24 05:04:31 +03:00
Deolys 7809806b83 Merge pull request 'webstar-project stubs api' (#3) from webstar-branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/3
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-22 22:47:01 +03:00
Deolys1 1aa0c36c84 post login fixed 2024-05-22 22:42:58 +03:00
Deolys1 7c3132c54b webstar-project stubs api 2024-05-22 15:11:46 +03:00
primakov 8fc85a7de8 Merge pull request 'fix problems with edateam stubs index.js' (#2) from edateam_branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/2
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-19 21:14:14 +03:00
NewPerson cb8b2cc5aa fix problems with edateam stubs index.js 2024-05-19 21:07:33 +03:00
primakov 6651215eeb a bit refresh deployment 2024-05-19 20:50:15 +03:00
primakov 80f8cef142 Merge pull request 'edateam_branch' (#1) from edateam_branch into master
Reviewed-on: https://git.inno-js.ru/bro-students/multy-stub/pulls/1
Reviewed-by: primakov <primakovpro@gmail.com>
2024-05-19 12:48:51 +03:00
WlfromB 5a57291523 index.js + edateam app use 2024-05-19 03:04:19 +03:00
WlfromB 39ab269f07 edateam stubs add 2024-05-19 03:01:32 +03:00
primakov 7cb23080bf search examples 2024-05-18 15:31:34 +03:00
primakov d74e4a8624 r-and-m jsons 2024-05-18 13:40:25 +03:00
1299 changed files with 8848 additions and 1740 deletions

No files matched your search

-45
View File
@@ -1,45 +0,0 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: [
'airbnb-base',
],
parserOptions: {
ecmaVersion: 12,
},
rules: {
indent: ['error', 4],
semi: ['warn', 'never'],
'object-curly-newline': ['warn', {
ObjectExpression: 'always',
ObjectPattern: {
multiline: true,
},
ImportDeclaration: 'never',
ExportDeclaration: {
multiline: true, minProperties: 3,
},
}],
'consistent-return': [0],
'prefer-const': [0],
'no-unused-vars': [0],
'no-console': [0],
'global-require': [0],
'no-plusplus': [0],
'no-underscore-dangle': [0],
'import/no-dynamic-require': [0],
'no-shadow': ['warn'],
'no-restricted-syntax': ['warn'],
'max-len': ['warn'],
'linebreak-style': [0],
'prefer-destructuring': [0],
'imoprt-order': [0],
'no-param-reassign': [1],
'no-await-in-loop': [1],
'no-return-assign': [1],
'spaced-comment': [1],
},
}
+1
View File
@@ -1,3 +1,4 @@
node_modules/
.env
.idea
coverage/
-1
View File
@@ -1 +0,0 @@
package-lock=true
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = {
port: 8044,
port: process.env.PORT ?? 8044,
mongoAddr: process.env.MONGO_ADDR || 'localhost',
mongoPort: 27017,
}
+4 -2
View File
@@ -1,14 +1,16 @@
FROM 'node:18'
FROM node:20
RUN mkdir -p /usr/src/app/server/
WORKDIR /usr/src/app/
COPY ./server /usr/src/app/server
COPY ./package.json /usr/src/app/package.json
COPY ./package-lock.json /usr/src/app/package-lock.json
COPY ./.serverrc.js /usr/src/app/.serverrc.js
# COPY ./.env /usr/src/app/.env
RUN npm i --only=prod
# RUN npm i --omit=dev
RUN npm ci
EXPOSE 8044
CMD ["npm", "run", "up:prod"]
Vendored
+7 -7
View File
@@ -1,7 +1,7 @@
pipeline {
agent {
docker {
image 'node:18'
image 'node:20'
}
}
@@ -10,7 +10,7 @@ pipeline {
steps {
sh 'node -v'
sh 'npm -v'
sh 'npm install'
sh 'npm ci'
}
}
@@ -22,15 +22,15 @@ pipeline {
stage('test') {
steps {
sh 'npm run test:start'
sh 'npm run test'
}
}
stage('clean-all') {
stage('archiving') {
steps {
sh 'rm -rf .[!.]*'
sh 'rm -rf ./*'
sh 'ls -a'
script {
archiveArtifacts artifacts: 'coverage/*/**'
}
}
}
}
+16
View File
@@ -0,0 +1,16 @@
import globals from "globals";
import pluginJs from "@eslint/js";
export default [
{ ignores: ['server/routers/old/*'] },
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
{
rules: {
semi: ['warn', 'never'],
'no-unused-vars': [0],
}
}
];
+201
View File
@@ -0,0 +1,201 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
/** @type {import('jest').Config} */
const config = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\alex\\AppData\\Local\\Temp\\jest",
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
"<rootDir>/server/routers/**/*.js"
],
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [
"\\\\node_modules\\\\",
"<rootDir>/server/routers/old"
],
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// A path to a custom dependency extractor
// dependencyExtractor: undefined,
// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,
// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },
// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
// preset: undefined,
// Run tests from one or more projects
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state before every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: undefined,
// Automatically restore mock state and implementation before every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",
// A map from regular expressions to paths to transformers
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
verbose: true,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};
module.exports = config;
+3833 -1606
View File
File diff suppressed because it is too large. Load diff
+14 -12
View File
@@ -4,16 +4,15 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "npx nodemon ./server",
"start": "cross-env PORT=8033 npx nodemon ./server",
"up:prod": "cross-env NODE_ENV=\"production\" node ./server",
"deploy:d:stop": "docker-compose down",
"deploy:d:build": "docker-compose build",
"deploy:d:up": "docker-compose up -d",
"deploy:d:stop": "docker compose down",
"deploy:d:build": "docker compose build",
"deploy:d:up": "docker compose up -d",
"redeploy": "npm run deploy:d:stop && npm run deploy:d:build && npm run deploy:d:up",
"eslint": "npx eslint ./server",
"eslint:fix": "npx eslint ./server --fix",
"test": "echo \"test complete\"",
"test:start": "start-server-and-test up:prod 8044 test"
"test": "jest"
},
"repository": {
"type": "git",
@@ -24,6 +23,7 @@
"license": "MIT",
"homepage": "https://bitbucket.org/online-mentor/multi-stub#readme",
"dependencies": {
"axios": "^1.7.7",
"bcrypt": "^5.1.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
@@ -37,17 +37,19 @@
"jsdom": "^22.1.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "^3.6.8",
"mysql": "^2.18.1",
"mongoose": "^8.7.1",
"pbkdf2-password": "^1.2.1",
"socket.io": "^4.7.1",
"start-server-and-test": "^1.13.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@eslint/js": "^9.12.0",
"@types/node": "18.17.1",
"eslint": "8.46.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.28.0",
"nodemon": "3.0.1"
"eslint": "^9.12.0",
"globals": "^15.11.0",
"jest": "^29.7.0",
"mockingoose": "^2.16.2",
"nodemon": "3.0.1",
"supertest": "^7.0.0"
}
}
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`todo list app get list 1`] = `
{
"body": [
{
"_id": "670f69b5796ce7a9069da2f7",
"created": "2024-10-16T07:22:29.042Z",
"id": "670f69b5796ce7a9069da2f7",
"items": [],
"title": "qqq",
},
],
"success": true,
}
`;
+34
View File
@@ -0,0 +1,34 @@
const { describe, it, expect } = require('@jest/globals')
const request = require('supertest')
const express = require('express')
const mockingoose = require('mockingoose')
const { ListModel } = require('../data/model/todo/list')
const todo = require('../routers/todo/routes')
const app = express()
app.use(todo)
const listExample = {
"title": "qqq",
"items": [],
"_id": "670f69b5796ce7a9069da2f7",
"created": "2024-10-16T07:22:29.042Z",
"id": "670f69b5796ce7a9069da2f7"
}
describe('todo list app', () => {
it('get list', (done) => {
mockingoose(ListModel)
.toReturn([listExample], 'find')
.toReturn(listExample, 'create')
request(app)
.get('/list')
.expect(200)
.then((response) => {
expect(response.body).toMatchSnapshot()
done()
})
})
})
+2
View File
@@ -0,0 +1,2 @@
exports.TODO_LIST_MODEL_NAME = 'TODO_LIST'
exports.TODO_ITEM_MODEL_NAME = 'TODO_ITEM'
+23
View File
@@ -0,0 +1,23 @@
const { Schema, model } = require('mongoose')
const { TODO_ITEM_MODEL_NAME } = require('../../const')
const schema = new Schema({
title: String,
done: { type: Boolean, default: false },
closed: Date,
created: {
type: Date, default: () => new Date().toISOString(),
},
})
schema.set('toJSON', {
virtuals: true,
versionKey: false,
})
schema.virtual('id').get(function () {
return this._id.toHexString()
})
exports.ItemModel = model(TODO_ITEM_MODEL_NAME, schema)
+27
View File
@@ -0,0 +1,27 @@
const { Schema, model } = require('mongoose')
const { TODO_LIST_MODEL_NAME, TODO_ITEM_MODEL_NAME } = require('../../const')
const schema = new Schema({
title: String,
created: {
type: Date, default: () => new Date().toISOString(),
},
items: [{ type: Schema.Types.ObjectId, ref: TODO_ITEM_MODEL_NAME }],
})
schema.set('toJSON', {
virtuals: true,
versionKey: false,
})
schema.virtual('id').get(function () {
return this._id.toHexString()
})
schema.method('addItem', async function (itemObjectId) {
this.items.push(itemObjectId)
await this.save()
})
exports.ListModel = model(TODO_LIST_MODEL_NAME, schema)
+4 -20
View File
@@ -7,6 +7,8 @@ const app = express()
const cors = require('cors')
require('dotenv').config()
exports.app = app
const config = require('../.serverrc')
const { setIo } = require('./io')
@@ -40,26 +42,8 @@ app.use(require('./root'))
/**
* Добавляйте сюда свои routers.
*/
app.use('/lobsters', require('./routers/lobsters'))
app.use('/example', require('./routers/example'))
// app.use('/coder', require('./routers/coder'))
//app.use('/stc-21-03', require('./routers/stc-21-03'))
//app.use('/stc-21', require('./routers/stc'))
//app.use('/stc-22-24', require('./routers/stc-22-24'))
// app.use('/bushou-api', require('./routers/bushou'))
// app.use('/uryndyklar-api', require('./routers/uryndyklar'))
// app.use('/neptunium', require('./routers/neptunium'))
// app.use('/music-learn', require('./routers/music-learn'))
// app.use('/publicium', require('./routers/publicium'))
// app.use('/task-boss', require('./routers/task-boss'))
// app.use('/car-wash', require('./routers/car-wash'))
app.use('/zoom-bar', require('./routers/zoom-bar'))
//app.use('/basket', require('./routers/basket'))
//app.use('/easy-project', require('./routers/easy-project'))
//app.use('/sugarbun', require('./routers/sugarbun'))
app.use('/epja-2023-2', require('./routers/epja-2023-2'))
require('./routers/hub-video')
app.use('/epja-2024-1', require('./routers/epja-2024-1'))
app.use('/todo', require('./routers/todo/routes'))
app.use(require('./error'))
+17 -2
View File
@@ -1,17 +1,32 @@
const router = require('express').Router()
const fs = require('fs')
const path = require('path')
const router = require('express').Router()
const mongoose = require('mongoose')
const pkg = require('../package.json')
require('./utils/mongoose')
const folderPath = path.resolve(__dirname, './routers')
const folders = fs.readdirSync(folderPath)
router.get('/', (req, res) => {
router.get('/', async (req, res) => {
res.send(`
<h1>multy stub is working v${pkg.version}</h1>
<ul>
${folders.map((f) => `<li>${f}</li>`).join('')}
</ul>
<h2>models</h2>
<ul>${
(await Promise.all(
(
await mongoose.modelNames()).map(async (name) => {
const count = await mongoose.model(name).countDocuments()
return `<li>${name} - ${count}</li>`
}
)
)).map(t => t).join(' ')
}</ul>
`)
})
@@ -0,0 +1,147 @@
const adminRouter = require('express').Router()
const fs = require('fs')
const path = require('path')
const { TOKEN } = require('../const')
require('dotenv').config()
const dataFilePath = path.join(__dirname, '../data.json')
let data = require('../data.json')
const verifyToken = (req, res, next) => {
const token = req.headers['authorization']
if (token === TOKEN) {
next()
} else {
res.status(403).send({ 'status': 'Failed', 'data': 'Invalid token' })
}
}
const saveData = (data) => {
fs.writeFileSync(dataFilePath, JSON.stringify(data, null, 2), 'utf-8')
}
adminRouter.post('/edit/nickname', verifyToken, (req, res) => {
const { name, colored } = req.body
if (!name || !colored) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Nickname is required' })
}
data.nickname = { name, colored }
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Nickname updated successfully' })
})
adminRouter.post('/edit/tech-stack', verifyToken, (req, res) => {
const { techStack } = req.body
if (!techStack || !Array.isArray(techStack)) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Valid tech stack is required' })
}
data.techStack = techStack
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Tech stack updated successfully' })
})
adminRouter.post('/edit/city', verifyToken, (req, res) => {
const { city } = req.body
if (!city) {
return res.status(400).send({ 'status': 'Failed', 'data': 'City is required' })
}
const isValid = typeof city === 'object' && 'name' in city && 'href' in city
if (!isValid) {
return res.status(400).send({ 'status': 'Failed', 'data': 'City must contain href and name' })
}
data.city = city
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'City updated successfully' })
})
adminRouter.post('/edit/github-repo', verifyToken, (req, res) => {
const { github } = req.body
if (!github) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Github is required' })
}
const isValid = typeof github === 'object' && 'author' in github && 'repo' in github
if (!isValid) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Github must contain author and repo' })
}
data.githubRepo = github
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Github updated successfully' })
})
adminRouter.post('/edit/nav-links', verifyToken, (req, res) => {
const { navLinks } = req.body
if (!navLinks || !Array.isArray(navLinks)) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Valid navLinks are required' })
}
const isValid = navLinks.every(link =>
link && typeof link === 'object' && 'href' in link && 'title' in link
)
if (!isValid) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Each navLink must contain href and title' })
}
data.navLinks = navLinks
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Navigation links updated successfully' })
})
adminRouter.post('/edit/links', verifyToken, (req, res) => {
const { links } = req.body
if (!links || !Array.isArray(links)) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Valid links are required' })
}
const isValid = links.every(link =>
link && typeof link === 'object' && 'href' in link && 'title' in link
)
if (!isValid) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Each link must contain href and title' })
}
data.links = links
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Links updated successfully' })
})
adminRouter.post('/edit/projects', verifyToken, (req, res) => {
const { projects } = req.body
if (!projects) {
return res.status(400).send({ 'status': 'Failed', 'data': 'Projects are required' })
}
const projectFields = ['id', 'title', 'description', 'link', 'techStack', 'image']
const isValidProject = (project) => {
return projectFields.every(field => field && field in project)
}
const allProjectsValid = projects.every(project => isValidProject(project))
if (!allProjectsValid) {
return res.status(400).send({ 'status': 'Failed', 'data': 'All projects must contain ' + projectFields.join(", ") })
}
data.projects = projects
saveData(data)
res.status(200).send({ 'status': 'OK', 'data': 'Projects updated successfully' })
})
module.exports = adminRouter
@@ -0,0 +1,16 @@
const authRouter = require('express').Router()
const { TOKEN } = require('../const')
module.exports = authRouter
authRouter.post('/login', (req, res) => {
const { email, password } = req.body
console.log(`Login with email=${email} and password=${password}`)
if (email === 'admin@admin.admin' && password === 'admin') {
res.status(200).send({ 'status': 'OK', 'data': `${TOKEN}` })
} else {
res.status(401).send({ 'status': 'Failed!', 'data': 'Invalid email or password' })
}
})
+3
View File
@@ -0,0 +1,3 @@
const TOKEN = "ASDFGHJKLLKJHGFDSDFGHJKJHGF"
module.exports = { TOKEN }
+118
View File
@@ -0,0 +1,118 @@
{
"nickname": {
"name": "supercool",
"colored": "nickname"
},
"techStack": [
"React",
"Next.js",
"Svelte",
"SvelteKit",
"HTML",
"CSS",
"JavaScript",
"TypeScript",
"TailwindCSS",
"Styled-Components",
"Framer-Motion",
"shadcn-ui",
"Ant-Design",
"ESLint",
"Prettier",
"husky",
"lint-staged",
"Redux",
"RTK Query",
"Tanstack Query",
"Python",
"FastApi",
"Flask",
"SQLite",
"PostgreSQL",
"MongoDB",
"SQLAlchemy",
"Alembic",
"PyPy",
"poetry",
"pylint",
"GitHub Actions",
"GitLab CI/CD",
"Docker",
"Git"
],
"githubRepo": {
"author": "MishaBlin",
"repo": "EPJA_portfolio_app"
},
"city": {
"name": "Innopolis",
"href": "https://ru.wikipedia.org/wiki/Иннополис"
},
"navLinks": [
{
"href": "#about",
"title": "About"
},
{
"href": "#projects",
"title": "Projects"
}
],
"links": [
{
"href": "mailto:svyatoslavsvyatkin@yandex.ru",
"title": "Mail"
},
{
"href": "https://t.me/dmhd6219",
"title": "Telegram"
},
{
"href": "https://github.com/dmhd6219",
"title": "GitHub"
},
{
"href": "https://last.fm/user/dmhd",
"title": "LastFm"
},
{
"href": "https://pay.cloudtips.ru/p/02da9349",
"title": "Buy me a coffee"
}
],
"projects": [
{
"title": "Elasticsearch",
"description": "Elasticsearch is a distributed search and analytics engine, scalable data store and vector database optimized for speed and relevance on production-scale workloads.",
"link": "https://github.com/elastic/elasticsearch",
"techStack": [
"Java",
"Groovy"
],
"image": "https://datascientest.com/en/files/2023/04/Elasticsearch.jpg",
"id": "elasticsearch"
},
{
"title": "React-native",
"description": "React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.",
"link": "https://github.com/facebook/react-native",
"techStack": [
"C++",
"Javascript",
"Kotlin"
],
"image": "https://www.simplilearn.com/ice9/free_resources_article_thumb/React_Native_Tutorial.jpg",
"id": "react-native"
},
{
"title": "Zarr",
"description": "Zarr is a Python package providing an implementation of compressed, chunked, N-dimensional arrays, designed for use in parallel computing. See the documentation for more information.",
"link": "https://github.com/zarr-developers/zarr-python",
"techStack": [
"Python"
],
"image": "https://raw.githubusercontent.com/zarr-developers/community/main/logos/logo2.png",
"id": "zarr"
}
]
}
+11
View File
@@ -0,0 +1,11 @@
const authRouter = require('./auth')
const adminRouter = require('./admin')
const rootRouter = require('./root')
const router = require('express').Router()
module.exports = router
router.use(`/auth`, authRouter)
router.use(`/admin`, adminRouter)
router.use(`/`, rootRouter)
@@ -0,0 +1,44 @@
const rootRouter = require('express').Router()
const data = require('../data.json')
rootRouter.get('/get/nickname', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.nickname })
})
rootRouter.get('/get/tech-stack', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.techStack })
})
rootRouter.get('/get/github-repo', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.githubRepo })
})
rootRouter.get('/get/city', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.city })
})
rootRouter.get('/get/nav-links', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.navLinks })
})
rootRouter.get('/get/links', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.links })
})
rootRouter.get('/get/projects', (req, res) => {
res.status(200).send({ 'status': 'OK', 'data': data.projects })
})
rootRouter.get('/get/projects/:id', (req, res) => {
const { id } = req.params
const project = data.projects.find(p => p.id === id)
if (project) {
res.status(200).send({ status: 'OK', data: project })
} else {
res.status(404).send({ status: 'NOT_FOUND', message: 'Project not found' })
}
})
module.exports = rootRouter
@@ -0,0 +1,9 @@
const plantsRouter = require('./plants/getPlants')
const calendarRouter = require('./plants_calendar/index')
const router = require('express').Router()
module.exports = router
router.use('/plants',plantsRouter)
router.use('/plants_calendar',calendarRouter)
@@ -0,0 +1,6 @@
const CONFIG = {
CLIENT_ID: 'kD2JXj1faSCYAWdT4B069wQAx89CZAkXmzTinRvH',
CLIENT_SECRET: 'bJq7Uiwua52tHiLP80N60hALNtQX2wcE4Mj6yNA9OzG2iZbgHuqyeAs6WSWX6MNJdfv0Nqzb7OHta8qPZr4zxWBLTauleaMfraln3xFEvbXLDpi1Lcrwe7DxfgsQQ1E4',
}
module.exports = CONFIG
@@ -0,0 +1,143 @@
const express = require ('express')
const axios = require ('axios')
const plantsRouter = express.Router ()
const CONFIG = require ('./config')
async function getAccessToken () {
const formData = new FormData ()
formData.append ('grant_type', 'client_credentials')
formData.append ('client_id', CONFIG.CLIENT_ID)
formData.append ('client_secret', CONFIG.CLIENT_SECRET)
try {
const response = await axios.post (
'https://open.plantbook.io/api/v1/token/',
formData,
{
headers: {'Content-Type': 'multipart/form-data'},
}
)
if (response.data && response.data.access_token) {
console.log ('Access token retrieved:', response.data.access_token)
return response.data.access_token
} else {
console.error ('Error: access_token not found in response')
return null
}
} catch (error) {
console.error (
'Error fetching access token:',
error.response ? error.response.data : error.message
)
return null
}
}
async function fetchPlantData (plantId) {
const accessToken = await getAccessToken ()
if (!accessToken) {
return null
}
try {
const response = await axios.get (
`https://open.plantbook.io/api/v1/plant/detail/${encodeURIComponent (plantId)}/`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
)
return response.data
} catch (error) {
console.error (
'Error fetching plant data:',
error.response ? error.response.data : error.message
)
return null
}
}
plantsRouter.get ('/list', async (req, res) => {
const accessToken = await getAccessToken ()
if (!accessToken) {
res.status (500).send ({message: 'Error obtaining access token'})
return
}
try {
const alias = req.query.alias || 'monstera'
const response = await axios.get (
'https://open.plantbook.io/api/v1/plant/search',
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
params: {
alias: alias,
},
}
)
const plantsList = response.data.results
const plants = await Promise.all (
plantsList.map (async plant => {
const plantDetails = await fetchPlantData (plant.pid)
return {
id: plant.pid,
alias: plant.alias,
display_name: plant.display_name,
image_url: plantDetails ? plantDetails.image_url : null,
max_light: plantDetails ? plantDetails.max_light : null,
min_light: plantDetails ? plantDetails.min_light : null,
max_temp: plantDetails ? plantDetails.max_temp : null,
min_temp: plantDetails ? plantDetails.min_temp : null,
max_env_humid: plantDetails ? plantDetails.max_env_humid : null,
min_env_humid: plantDetails ? plantDetails.min_env_humid : null,
max_soil_moist: plantDetails ? plantDetails.max_soil_moist : null,
min_soil_moist: plantDetails ? plantDetails.min_soil_moist : null,
max_soil_ec: plantDetails ? plantDetails.max_soil_ec : null,
min_soil_ec: plantDetails ? plantDetails.min_soil_ec : null,
}
})
)
res.send ({results: plants})
} catch (error) {
console.error (
'Error fetching plant list:',
error.response ? error.response.data : error.message
)
res.status (500).send ({message: 'Error fetching plant list'})
}
})
plantsRouter.get ('/:id', async (req, res) => {
const plantId = req.params.id
const plantData = await fetchPlantData (plantId)
if (plantData) {
const detailedPlantData = {
id: plantData.pid,
display_name: plantData.display_name,
alias: plantData.alias,
max_light: plantData.max_light,
min_light: plantData.min_light,
max_temperature: plantData.max_temp,
min_temperature: plantData.min_temp,
max_humidity: plantData.max_env_humid,
min_humidity: plantData.min_env_humid,
max_soil_moisture: plantData.max_soil_moist,
min_soil_moisture: plantData.min_soil_moist,
max_soil_ec: plantData.max_soil_ec,
min_soil_ec: plantData.min_soil_ec,
image_url: plantData.image_url,
}
res.send (detailedPlantData)
} else {
res.status (404).send ({message: 'Plant not found'})
}
})
module.exports = plantsRouter
@@ -0,0 +1,42 @@
const express = require('express')
const plantsRouter = express.Router()
const plants = [
{
name: "Rose",
image: "https://ervanarium.com.br/wp-content/uploads/2019/03/cactus-3142589_1920.jpg",
frequency: 3,
startDate: "2024-10-09",
},
{
name: "Sunflower",
image: "https://avatars.mds.yandex.net/i?id=31da587c9aabc83ad3615023f91d7284781be06c-10701700-images-thumbs&n=13",
frequency: 3,
startDate: "2024-10-05",
},
]
const calculateWateringDates = (startDate, frequency) => {
const dates = []
const start = new Date(startDate)
for (let i = 0; i < 30; i += frequency) {
const nextWateringDate = new Date(start)
nextWateringDate.setDate(start.getDate() + i)
dates.push(nextWateringDate.toISOString().split('T')[0])
}
return dates
}
const plantsWithDates = plants.map(plant => ({
...plant,
wateringDates: calculateWateringDates(plant.startDate, plant.frequency),
}))
plantsRouter.get('/api/plants', (req, res) => {
res.json(plantsWithDates)
})
module.exports = plantsRouter
@@ -0,0 +1,73 @@
const authRouter = require('express').Router()
// For creating tokens
const jwt = require('jsonwebtoken')
const { TOKEN_KEY } = require('../key')
module.exports = authRouter
const { addUserToDB, getUserFromDB } = require('../db')
// Get a user by its id
authRouter.get('/:id', (req, res) => {
const user = getUserFromDB(req.params.id)
if (user) {
res.status(200).send({user})
} else {
res.status(404).send({message: 'User was not found'})
}
})
// For login (authorization)
authRouter.post('/login', (req, res) => {
const { name, password } = req.body
const user = getUserFromDB(name)
// Invalid identification
if (!user) {
res.status(401).send({message: 'Invalid credentials (id)'})
return
}
// Invalid authentication
if (!password || password !== user.password) {
res.status(401).send({message: 'Invalid credentials (password)'})
return
}
// Now, authorization
const token = jwt.sign({id: name}, TOKEN_KEY, {
expiresIn: '1h'
})
res.status(200).send({token})
})
authRouter.post('/reg', (req, res) => {
const { name, password, nickname } = req.body
const user = getUserFromDB(name)
// Invalid identification
if (user) {
res.status(409).send({message: 'Such id already exists'})
return
}
if (!name || !password || !nickname) {
res.status(401).send({message: 'Empty or invalid fields'})
return
}
// Add to 'DB'
const newUser = {id: name, password: password, nickname: nickname}
addUserToDB(newUser)
res.status(200).send({user: newUser})
})
@@ -0,0 +1,52 @@
[
{
"nickname": "Alice Johnson",
"password": "1234",
"id": "alice"
},
{
"nickname": "Bob Smith",
"password": "1234",
"id": "bobsm"
},
{
"nickname": "Charlie Brown",
"password": "1234",
"id": "charl"
},
{
"nickname": "David Clark",
"password": "1234",
"id": "david"
},
{
"nickname": "Eve Adams",
"password": "1234",
"id": "evead"
},
{
"nickname": "Frank Wright",
"password": "1234",
"id": "frank"
},
{
"nickname": "Grace Lee",
"password": "1234",
"id": "grace"
},
{
"nickname": "Hannah Scott",
"password": "1234",
"id": "hanna"
},
{
"nickname": "Ian Davis",
"password": "1234",
"id": "ianda"
},
{
"nickname": "Jill Thompson",
"password": "1234",
"id": "jillt"
}
]
@@ -0,0 +1,64 @@
const changeRouter = require('express').Router()
module.exports = changeRouter
const { getUserFromDB, deleteUserFromDB, addUserToDB } = require('../db')
changeRouter.post('/nickname', (req, res) => {
const { id, newNickname } = req.body
const user = getUserFromDB(id)
// Invalid identification
if (!user) {
res.status(401).send({message: 'Invalid credentials (id)'})
return
}
const updatedUser = {
"nickname": newNickname,
"password": user.password,
"id": user.id
}
// Delete the old one
deleteUserFromDB(id)
// Insert updated
addUserToDB(updatedUser)
res.status(200).send({})
})
changeRouter.post('/password', (req, res) => {
const { id, newPassword } = req.body
const user = getUserFromDB(id)
// Invalid identification
if (!user) {
res.status(401).send({message: 'Invalid credentials (id)'})
return
}
// Delete the old one
deleteUserFromDB(id)
// Insert updated
const updatedUser = {
"nickname": user.nickname,
"password": newPassword,
"id": user.id
}
addUserToDB(updatedUser)
res.status(200).send({})
})
changeRouter.delete('/:id', (req, res) => {
const { id } = req.params
deleteUserFromDB(id)
})
@@ -0,0 +1,662 @@
[
{
"id1": "alice",
"id2": "bobsm",
"messages": [
{
"data": "Hello Bob!",
"senderId": "alice",
"recipientId": "bobsm",
"timestamp": "09.10.2024 07:00:00"
},
{
"data": "Hey Alice, how are you?",
"senderId": "bobsm",
"recipientId": "alice",
"timestamp": "09.10.2024 07:05:00"
},
{
"data": "I'm good, thanks for asking.",
"senderId": "alice",
"recipientId": "bobsm",
"timestamp": "09.10.2024 07:10:00"
},
{
"data": "Glad to hear!",
"senderId": "bobsm",
"recipientId": "alice",
"timestamp": "09.10.2024 07:15:00"
}
]
},
{
"id1": "alice",
"id2": "charl",
"messages": [
{
"data": "How's the project going?",
"senderId": "alice",
"recipientId": "charl",
"timestamp": "09.10.2024 07:20:00"
},
{
"data": "It's coming along, almost done!",
"senderId": "charl",
"recipientId": "alice",
"timestamp": "09.10.2024 07:25:00"
},
{
"data": "That's great to hear!",
"senderId": "alice",
"recipientId": "charl",
"timestamp": "09.10.2024 07:30:00"
},
{
"data": "Thanks for checking in.",
"senderId": "charl",
"recipientId": "alice",
"timestamp": "09.10.2024 07:35:00"
}
]
},
{
"id1": "alice",
"id2": "david",
"messages": [
{
"data": "Did you get the files?",
"senderId": "david",
"recipientId": "alice",
"timestamp": "09.10.2024 07:40:00"
},
{
"data": "Yes, I did. Thank you!",
"senderId": "alice",
"recipientId": "david",
"timestamp": "09.10.2024 07:45:00"
},
{
"data": "You're welcome.",
"senderId": "david",
"recipientId": "alice",
"timestamp": "09.10.2024 07:50:00"
},
{
"data": "Let me know if you need anything else.",
"senderId": "alice",
"recipientId": "david",
"timestamp": "09.10.2024 07:55:00"
}
]
},
{
"id1": "alice",
"id2": "frank",
"messages": [
{
"data": "Can you review this document for me?",
"senderId": "alice",
"recipientId": "frank",
"timestamp": "09.10.2024 08:20:00"
},
{
"data": "Sure, I'll take a look.",
"senderId": "frank",
"recipientId": "alice",
"timestamp": "09.10.2024 08:25:00"
},
{
"data": "Thanks, much appreciated!",
"senderId": "alice",
"recipientId": "frank",
"timestamp": "09.10.2024 08:30:00"
},
{
"data": "No problem.",
"senderId": "frank",
"recipientId": "alice",
"timestamp": "09.10.2024 08:35:00"
}
]
},
{
"id1": "alice",
"id2": "grace",
"messages": [
{
"data": "Hey Grace, let's meet up for coffee!",
"senderId": "alice",
"recipientId": "grace",
"timestamp": "09.10.2024 08:40:00"
},
{
"data": "Sounds good, when are you free?",
"senderId": "grace",
"recipientId": "alice",
"timestamp": "09.10.2024 08:45:00"
},
{
"data": "How about tomorrow afternoon?",
"senderId": "alice",
"recipientId": "grace",
"timestamp": "09.10.2024 08:50:00"
},
{
"data": "Works for me!",
"senderId": "grace",
"recipientId": "alice",
"timestamp": "09.10.2024 08:55:00"
}
]
},
{
"id1": "alice",
"id2": "hanna",
"messages": [
{
"data": "Hannah, do you have a moment?",
"senderId": "alice",
"recipientId": "hanna",
"timestamp": "09.10.2024 09:00:00"
},
{
"data": "Sure, what's up?",
"senderId": "hanna",
"recipientId": "alice",
"timestamp": "09.10.2024 09:05:00"
},
{
"data": "Just wanted to check on the report.",
"senderId": "alice",
"recipientId": "hanna",
"timestamp": "09.10.2024 09:10:00"
},
{
"data": "I'll send it soon.",
"senderId": "hanna",
"recipientId": "alice",
"timestamp": "09.10.2024 09:15:00"
}
]
},
{
"id1": "alice",
"id2": "ianda",
"messages": [
{
"data": "Ian, have you completed the review?",
"senderId": "alice",
"recipientId": "ianda",
"timestamp": "09.10.2024 09:20:00"
},
{
"data": "Yes, I sent my feedback.",
"senderId": "ianda",
"recipientId": "alice",
"timestamp": "09.10.2024 09:25:00"
},
{
"data": "Thanks for that.",
"senderId": "alice",
"recipientId": "ianda",
"timestamp": "09.10.2024 09:30:00"
},
{
"data": "Anytime!",
"senderId": "ianda",
"recipientId": "alice",
"timestamp": "09.10.2024 09:35:00"
}
]
},
{
"id1": "alice",
"id2": "jillt",
"messages": [
{
"data": "Jill, let's schedule a catch-up meeting.",
"senderId": "alice",
"recipientId": "jillt",
"timestamp": "09.10.2024 09:40:00"
},
{
"data": "Sounds good, when works for you?",
"senderId": "jillt",
"recipientId": "alice",
"timestamp": "09.10.2024 09:45:00"
},
{
"data": "Tomorrow afternoon?",
"senderId": "alice",
"recipientId": "jillt",
"timestamp": "09.10.2024 09:50:00"
},
{
"data": "That works for me!",
"senderId": "jillt",
"recipientId": "alice",
"timestamp": "09.10.2024 09:55:00"
}
]
},
{
"id1": "alice",
"id2": "evead",
"messages": [
{
"data": "Eve, did you send the schedule?",
"senderId": "alice",
"recipientId": "evead",
"timestamp": "09.10.2024 10:00:00"
},
{
"data": "Yes, just sent it.",
"senderId": "evead",
"recipientId": "alice",
"timestamp": "09.10.2024 10:05:00"
},
{
"data": "Thanks, much appreciated!",
"senderId": "alice",
"recipientId": "evead",
"timestamp": "09.10.2024 10:10:00"
},
{
"data": "No problem!",
"senderId": "evead",
"recipientId": "alice",
"timestamp": "09.10.2024 10:15:00"
}
]
},
{
"id1": "bobsm",
"id2": "charl",
"messages": [
{
"data": "How's everything going?",
"senderId": "bobsm",
"recipientId": "charl",
"timestamp": "09.10.2024 10:20:00"
},
{
"data": "Pretty good, how about you?",
"senderId": "charl",
"recipientId": "bobsm",
"timestamp": "09.10.2024 10:25:00"
},
{
"data": "Can't complain!",
"senderId": "bobsm",
"recipientId": "charl",
"timestamp": "09.10.2024 10:30:00"
},
{
"data": "Glad to hear that.",
"senderId": "charl",
"recipientId": "bobsm",
"timestamp": "09.10.2024 10:35:00"
}
]
},
{
"id1": "bobsm",
"id2": "david",
"messages": [
{
"data": "Can you send the report?",
"senderId": "bobsm",
"recipientId": "david",
"timestamp": "09.10.2024 10:40:00"
},
{
"data": "I'll send it in an hour.",
"senderId": "david",
"recipientId": "bobsm",
"timestamp": "09.10.2024 10:45:00"
},
{
"data": "Perfect, thanks.",
"senderId": "bobsm",
"recipientId": "david",
"timestamp": "09.10.2024 10:50:00"
},
{
"data": "No problem.",
"senderId": "david",
"recipientId": "bobsm",
"timestamp": "09.10.2024 10:55:00"
}
]
},
{
"id1": "charl",
"id2": "evead",
"messages": [
{
"data": "Hey Eve, how's it going?",
"senderId": "charl",
"recipientId": "evead",
"timestamp": "09.10.2024 11:00:00"
},
{
"data": "Good, how about you?",
"senderId": "evead",
"recipientId": "charl",
"timestamp": "09.10.2024 11:05:00"
},
{
"data": "Can't complain!",
"senderId": "charl",
"recipientId": "evead",
"timestamp": "09.10.2024 11:10:00"
},
{
"data": "Glad to hear.",
"senderId": "evead",
"recipientId": "charl",
"timestamp": "09.10.2024 11:15:00"
}
]
},
{
"id1": "charl",
"id2": "frank",
"messages": [
{
"data": "Do you have time to talk today?",
"senderId": "charl",
"recipientId": "frank",
"timestamp": "09.10.2024 11:20:00"
},
{
"data": "I have a meeting, but I can chat afterward.",
"senderId": "frank",
"recipientId": "charl",
"timestamp": "09.10.2024 11:25:00"
},
{
"data": "Sounds good.",
"senderId": "charl",
"recipientId": "frank",
"timestamp": "09.10.2024 11:30:00"
},
{
"data": "I'll message you after.",
"senderId": "frank",
"recipientId": "charl",
"timestamp": "09.10.2024 11:35:00"
}
]
},
{
"id1": "david",
"id2": "frank",
"messages": [
{
"data": "Did you review the document?",
"senderId": "david",
"recipientId": "frank",
"timestamp": "09.10.2024 11:40:00"
},
{
"data": "Yes, it's all good.",
"senderId": "frank",
"recipientId": "david",
"timestamp": "09.10.2024 11:45:00"
},
{
"data": "Great, thanks for the quick turnaround!",
"senderId": "david",
"recipientId": "frank",
"timestamp": "09.10.2024 11:50:00"
},
{
"data": "No worries!",
"senderId": "frank",
"recipientId": "david",
"timestamp": "09.10.2024 11:55:00"
}
]
},
{
"id1": "david",
"id2": "grace",
"messages": [
{
"data": "Grace, can you send the updated schedule?",
"senderId": "david",
"recipientId": "grace",
"timestamp": "09.10.2024 12:00:00"
},
{
"data": "Yes, I'll send it in a few minutes.",
"senderId": "grace",
"recipientId": "david",
"timestamp": "09.10.2024 12:05:00"
},
{
"data": "Thanks, much appreciated!",
"senderId": "david",
"recipientId": "grace",
"timestamp": "09.10.2024 12:10:00"
},
{
"data": "You're welcome!",
"senderId": "grace",
"recipientId": "david",
"timestamp": "09.10.2024 12:15:00"
}
]
},
{
"id1": "frank",
"id2": "grace",
"messages": [
{
"data": "How are you today?",
"senderId": "frank",
"recipientId": "grace",
"timestamp": "09.10.2024 12:20:00"
},
{
"data": "I'm doing well, thanks for asking.",
"senderId": "grace",
"recipientId": "frank",
"timestamp": "09.10.2024 12:25:00"
},
{
"data": "Glad to hear that.",
"senderId": "frank",
"recipientId": "grace",
"timestamp": "09.10.2024 12:30:00"
},
{
"data": "How about you?",
"senderId": "grace",
"recipientId": "frank",
"timestamp": "09.10.2024 12:35:00"
}
]
},
{
"id1": "frank",
"id2": "hanna",
"messages": [
{
"data": "Did you attend the meeting?",
"senderId": "frank",
"recipientId": "hanna",
"timestamp": "09.10.2024 12:40:00"
},
{
"data": "Yes, it was productive.",
"senderId": "hanna",
"recipientId": "frank",
"timestamp": "09.10.2024 12:45:00"
},
{
"data": "Good to hear!",
"senderId": "frank",
"recipientId": "hanna",
"timestamp": "09.10.2024 12:50:00"
},
{
"data": "Indeed, lots to follow up on.",
"senderId": "hanna",
"recipientId": "frank",
"timestamp": "09.10.2024 12:55:00"
}
]
},
{
"id1": "grace",
"id2": "hanna",
"messages": [
{
"data": "Can we meet later today?",
"senderId": "grace",
"recipientId": "hanna",
"timestamp": "09.10.2024 01:00:00"
},
{
"data": "Sure, what's a good time?",
"senderId": "hanna",
"recipientId": "grace",
"timestamp": "09.10.2024 01:05:00"
},
{
"data": "How about 3?",
"senderId": "grace",
"recipientId": "hanna",
"timestamp": "09.10.2024 01:10:00"
},
{
"data": "Works for me.",
"senderId": "hanna",
"recipientId": "grace",
"timestamp": "09.10.2024 01:15:00"
}
]
},
{
"id1": "grace",
"id2": "ianda",
"messages": [
{
"data": "Ian, did you get the message I sent?",
"senderId": "grace",
"recipientId": "ianda",
"timestamp": "09.10.2024 01:20:00"
},
{
"data": "Yes, I'll respond soon.",
"senderId": "ianda",
"recipientId": "grace",
"timestamp": "09.10.2024 01:25:00"
},
{
"data": "Thanks, appreciate it!",
"senderId": "grace",
"recipientId": "ianda",
"timestamp": "09.10.2024 01:30:00"
},
{
"data": "You're welcome!",
"senderId": "ianda",
"recipientId": "grace",
"timestamp": "09.10.2024 01:35:00"
}
]
},
{
"id1": "hanna",
"id2": "ianda",
"messages": [
{
"data": "Ian, do you have a minute?",
"senderId": "hanna",
"recipientId": "ianda",
"timestamp": "09.10.2024 01:40:00"
},
{
"data": "Yes, what do you need?",
"senderId": "ianda",
"recipientId": "hanna",
"timestamp": "09.10.2024 01:45:00"
},
{
"data": "Just a quick update on the project.",
"senderId": "hanna",
"recipientId": "ianda",
"timestamp": "09.10.2024 01:50:00"
},
{
"data": "I'll email you the details.",
"senderId": "ianda",
"recipientId": "hanna",
"timestamp": "09.10.2024 01:55:00"
}
]
},
{
"id1": "hanna",
"id2": "jillt",
"messages": [
{
"data": "Jill, can we talk tomorrow?",
"senderId": "hanna",
"recipientId": "jillt",
"timestamp": "09.10.2024 02:00:00"
},
{
"data": "Yes, I'm free after 2.",
"senderId": "jillt",
"recipientId": "hanna",
"timestamp": "09.10.2024 02:05:00"
},
{
"data": "Perfect, see you then.",
"senderId": "hanna",
"recipientId": "jillt",
"timestamp": "09.10.2024 02:10:00"
},
{
"data": "Looking forward to it.",
"senderId": "jillt",
"recipientId": "hanna",
"timestamp": "09.10.2024 02:15:00"
}
]
},
{
"id1": "ianda",
"id2": "jillt",
"messages": [
{
"data": "Jill, I have the files you requested.",
"senderId": "ianda",
"recipientId": "jillt",
"timestamp": "09.10.2024 02:20:00"
},
{
"data": "Thanks, please send them over.",
"senderId": "jillt",
"recipientId": "ianda",
"timestamp": "09.10.2024 02:25:00"
},
{
"data": "I'll send them right now.",
"senderId": "ianda",
"recipientId": "jillt",
"timestamp": "09.10.2024 02:30:00"
},
{
"data": "Great, thanks again!",
"senderId": "jillt",
"recipientId": "ianda",
"timestamp": "09.10.2024 02:35:00"
}
]
}
]
@@ -0,0 +1,86 @@
const chatRouter = require('express').Router()
module.exports = chatRouter
const { getChatFromDB, getUsersChats, addChatToDB, getUserFromDB,
addMessageToChat} = require('../db')
chatRouter.get('/item/:id1/:id2', (req, res) => {
const { id1, id2 } = req.params
if (id1 === id2) {
res.status(400).send({message: 'Ids should be different'})
return
}
const chat = getChatFromDB(id1, id2)
if (chat) {
res.status(200).send({chat})
} else {
res.status(404).send({message: 'Chat was not found'})
}
})
chatRouter.post('/item/:id1/:id2', (req, res) => {
const { id1, id2 } = req.params
if (id1 === id2) {
res.status(400).send({message: 'Ids should be different'})
return
}
const chat = getChatFromDB(id1, id2)
if (chat) {
// Chat already exists
res.status(200).send({chat})
} else {
if (!getUserFromDB(id1) || !getUserFromDB(id2)) {
res.status(404).send({message: 'Such interlocutor does not exist'})
} else {
// Creating new chat
const newChat = {
id1: id1,
id2: id2,
messages: []
}
addChatToDB(newChat)
res.status(200).send({newChat})
}
}
})
chatRouter.get('/list/:id', (req, res) => {
const { id } = req.params
const userChats = getUsersChats(id)
if (!userChats) {
res.status(404).send({message: 'Error with retrieving chats'})
} else {
res.status(200).send({chats: userChats})
}
})
chatRouter.post('/message/:sender/:receiver', (req, res) => {
const { sender, receiver } = req.params
const { message } = req.body
const chat = getChatFromDB(sender, receiver)
if (!chat) {
// Chat already exists
res.status(400).send({message: "Such chat does not exist"})
} else {
if (!getUserFromDB(sender) || !getUserFromDB(receiver)) {
res.status(404).send({message: 'Such people do not exist'})
} else {
// Add new message
addMessageToChat(chat, message)
res.status(200).send({})
}
}
})
@@ -0,0 +1,74 @@
// Read already defined users (pseudo-DB)
const users = require('./auth/users.json')
const chats = require('./chat/chats.json')
const getUserFromDB = (userID) => {
if (!userID) {return false}
// Accessing 'DB'
const user = users.find((user) => user.id === userID)
if (user) {
return user
} else {
return false
}
}
const deleteUserFromDB = (userID) => {
const index = users.findIndex(item => item.id === userID)
if (index !== -1) {
users.splice(index, 1)
}
}
const addUserToDB = (user) => {
users.push(user)
}
const getChatFromDB = (firstID, secondID) => {
if (!firstID || !secondID) {return false}
// Accessing 'DB'
const chat = chats.find((item) =>
(item.id1 === firstID && item.id2 === secondID) || (item.id1 === secondID && item.id2 === firstID))
if (chat) {
return chat
} else {
return false
}
}
const getUsersChats = (userID) => {
if (!userID) {return false}
const userChats = chats.filter((chat) => (chat.id1 === userID || chat.id2 === userID))
if (userChats) {
return userChats
} else {
return false
}
}
const addMessageToChat = (chat, msg) => {
chat.messages.push(msg)
}
const deleteChatFromDB = (firstID, secondID) => {
const index = chats.findIndex(item =>
(item.id1 === firstID && item.id2 === secondID) || (item.id1 === secondID && item.id2 === firstID))
if (index !== -1) {
chats.splice(index, 1)
}
}
const addChatToDB = (chat) => {
chats.push(chat)
}
module.exports = {users, chats, getUserFromDB, getChatFromDB, addUserToDB,
deleteUserFromDB, addChatToDB, deleteChatFromDB, getUsersChats, addMessageToChat}
@@ -0,0 +1,17 @@
const changeRouter = require("./change")
const authRouter = require("./auth")
const chatRouter = require("./chat")
const router = require('express').Router()
const delay = require('./middlewares/delay')
const verify = require('./middlewares/verify')
module.exports = router
// router.use(delay(300));
// router.use('/books', delay, booksRouter);
router.use('/auth', authRouter)
router.use('/change', verify, changeRouter)
router.use('/chat', verify, chatRouter)
@@ -0,0 +1,3 @@
const TOKEN_KEY = '5frv12e4few3r'
module.exports = { TOKEN_KEY }
@@ -0,0 +1,5 @@
const delay = (ms = 1000) => (req, res, next) => {
setTimeout(next, ms)
}
module.exports = delay
@@ -0,0 +1,22 @@
const jwt = require('jsonwebtoken')
const { TOKEN_KEY } = require('../key')
function verifyToken(req, res, next) {
const token = req.headers['authorization']?.split(' ')[1]
if (!token) {
return res.status(401).send({ message: 'No token provided' })
}
// Verify token
jwt.verify(token, TOKEN_KEY, (err, decoded) => {
if (err) {
return res.status(401).send({ message: 'Unauthorized' })
}
next() // Proceed to the next middleware or route
})
}
module.exports = verifyToken
+10
View File
@@ -0,0 +1,10 @@
const { Router } = require('express')
const router = Router()
router.use('/enterfront', require('./enterfront/index'))
router.use('/cats', require('./cats/index'))
router.use('/ecliptica', require('./ecliptica/index'))
module.exports = router
-19
View File
@@ -1,19 +0,0 @@
const router = require('express').Router()
const first = router.get('/first', (req, res) => {
res.send({
success: true,
warnings: [{
title: 'Внимание',
text: 'Данный api создан для примера!',
}],
})
/**
* Этот эндпоинт будет доступен по адресу http://89.223.91.151:8080/multystub/example/first
*/
})
router.use('/example-api', first)
module.exports = router
File renamed without changes.
File renamed without changes.
@@ -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'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 1299 files, more files were not shown because too many files have changed in this diff. Show more