Compare commits

..

2 Commits

Author SHA1 Message Date
Ruslan Zagitov
4d621c8bbe chore: add new dictionary 2024-12-27 23:32:54 +03:00
Ruslan Zagitov
ab8a9ebc99 feat: add '/units' endpoints; add 'put' and 'delete' requests to '/dictionaries' endpoint 2024-12-27 23:15:26 +03:00
15 changed files with 1677 additions and 1888 deletions

1
.gitignore vendored
View File

@@ -2,4 +2,3 @@ node_modules/
.env .env
.idea .idea
coverage/ coverage/
server/log/

View File

@@ -1,6 +1,6 @@
FROM node:20 FROM node:20
RUN mkdir -p /usr/src/app/server/log/ RUN mkdir -p /usr/src/app/server/
WORKDIR /usr/src/app/ WORKDIR /usr/src/app/
COPY ./server /usr/src/app/server COPY ./server /usr/src/app/server

View File

@@ -2,7 +2,6 @@ version: "3"
volumes: volumes:
ms_volume8: ms_volume8:
ms_logs:
services: services:
mongoDb: mongoDb:
@@ -16,8 +15,6 @@ services:
# build: . # build: .
image: bro.js/ms/bh:$TAG image: bro.js/ms/bh:$TAG
restart: always restart: always
volumes:
- ms_logs:/usr/src/app/server/log
ports: ports:
- 8044:8044 - 8044:8044
environment: environment:

3076
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,34 +23,33 @@
"license": "MIT", "license": "MIT",
"homepage": "https://bitbucket.org/online-mentor/multi-stub#readme", "homepage": "https://bitbucket.org/online-mentor/multi-stub#readme",
"dependencies": { "dependencies": {
"axios": "^1.7.9", "axios": "^1.7.7",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.0",
"body-parser": "^1.20.3", "body-parser": "^1.19.0",
"cookie-parser": "^1.4.7", "cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"crypto-js": "^4.2.0", "crypto-js": "^4.1.1",
"dotenv": "^16.4.7", "dotenv": "^16.3.1",
"express": "5.0.1", "express": "^4.18.2",
"express-jwt": "^8.5.1", "express-jwt": "^8.4.1",
"express-session": "^1.18.1", "express-session": "^1.17.3",
"jsdom": "^25.0.1", "jsdom": "^22.1.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^8.5.1",
"mongodb": "^6.12.0", "mongodb": "^3.6.8",
"mongoose": "^8.9.2", "mongoose": "^8.7.1",
"morgan": "^1.10.0",
"pbkdf2-password": "^1.2.1", "pbkdf2-password": "^1.2.1",
"rotating-file-stream": "^3.2.5", "socket.io": "^4.7.1",
"socket.io": "^4.8.1", "uuid": "^9.0.0"
"uuid": "^11.0.3"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.17.0", "@eslint/js": "^9.12.0",
"@types/node": "22.10.2", "@types/node": "18.17.1",
"eslint": "^9.17.0", "eslint": "^9.12.0",
"globals": "^15.14.0", "globals": "^15.11.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"mockingoose": "^2.16.2", "mockingoose": "^2.16.2",
"nodemon": "3.1.9", "nodemon": "3.0.1",
"supertest": "^7.0.0" "supertest": "^7.0.0"
} }
} }

View File

@@ -6,7 +6,6 @@ module.exports = (err, req, res, next) => {
success: false, error: 'Токен авторизации не найден', success: false, error: 'Токен авторизации не найден',
}) })
} }
res.status(400).send({ res.status(400).send({
success: false, error: err.message || 'Что-то пошло не так', success: false, error: err.message || 'Что-то пошло не так',
}) })

View File

@@ -1,95 +1,57 @@
const express = require("express") const express = require('express')
const bodyParser = require("body-parser") const bodyParser = require('body-parser')
const cookieParser = require("cookie-parser") const cookieParser = require('cookie-parser')
const session = require("express-session") const session = require('express-session')
const morgan = require("morgan")
const path = require("path")
const rfs = require("rotating-file-stream")
const app = express() const app = express()
require("dotenv").config() const cors = require('cors')
require('dotenv').config()
exports.app = app exports.app = app
const accessLogStream = rfs.createStream("access.log", { const config = require('../.serverrc')
size: "10M", const { setIo } = require('./io')
interval: "1d",
compress: "gzip",
path: path.join(__dirname, "log"),
})
const errorLogStream = rfs.createStream("error.log", {
size: "10M",
interval: "1d",
compress: "gzip",
path: path.join(__dirname, "log"),
})
const config = require("../.serverrc")
const { setIo } = require("./io")
app.use(cookieParser()) app.use(cookieParser())
app.use( app.options('*', cors())
morgan("combined", { app.use(cors())
stream: accessLogStream,
skip: function (req, res) {
return res.statusCode >= 400
},
})
)
// log all requests to access.log
app.use(
morgan("combined", {
stream: errorLogStream,
skip: function (req, res) {
console.log('statusCode', res.statusCode, res.statusCode <= 400)
return res.statusCode < 400
},
})
)
const server = setIo(app) const server = setIo(app)
const sess = { const sess = {
secret: "super-secret-key", secret: 'super-secret-key',
resave: true, resave: true,
saveUninitialized: true, saveUninitialized: true,
cookie: {}, cookie: {
},
} }
if (app.get("env") === "production") { if (app.get('env') === 'production') {
app.set("trust proxy", 1) app.set('trust proxy', 1)
sess.cookie.secure = true sess.cookie.secure = true
} }
app.use(session(sess)) app.use(session(sess))
app.use( app.use(bodyParser.json({
bodyParser.json({ limit: '50mb',
limit: "50mb", }))
}) app.use(bodyParser.urlencoded({
) limit: '50mb',
app.use(
bodyParser.urlencoded({
limit: "50mb",
extended: true, extended: true,
}) }))
) app.use(require('./root'))
app.use(require("./root"))
/** /**
* Добавляйте сюда свои routers. * Добавляйте сюда свои routers.
*/ */
app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1")) app.use('/kfu-m-24-1', require('./routers/kfu-m-24-1'))
app.use("/epja-2024-1", require("./routers/epja-2024-1")) app.use('/epja-2024-1', require('./routers/epja-2024-1'))
app.use("/todo", require("./routers/todo/routes")) app.use('/todo', require('./routers/todo/routes'))
app.use("/dogsitters-finder", require("./routers/dogsitters-finder")) app.use('/dogsitters-finder', require('./routers/dogsitters-finder'))
app.use("/kazan-explore", require("./routers/kazan-explore")) app.use('/kazan-explore', require('./routers/kazan-explore'))
app.use("/edateam", require("./routers/edateam-legacy")) app.use('/edateam', require('./routers/edateam-legacy'))
app.use("/dry-wash", require("./routers/dry-wash")) app.use('/dry-wash', require('./routers/dry-wash'))
app.use("/freetracker", require("./routers/freetracker")) app.use('/freetracker', require('./routers/freetracker'))
app.use("/dhs-testing", require("./routers/dhs-testing")) app.use('/dhs-testing', require('./routers/dhs-testing'))
app.use(require("./error")) app.use(require('./error'))
server.listen(config.port, () => server.listen(config.port, () => console.log(`Listening on http://localhost:${config.port}`))
console.log(`Listening on http://localhost:${config.port}`)
)

View File

@@ -10,7 +10,6 @@ const folderPath = path.resolve(__dirname, './routers')
const folders = fs.readdirSync(folderPath) const folders = fs.readdirSync(folderPath)
router.get('/', async (req, res) => { router.get('/', async (req, res) => {
// throw new Error('check error message')
res.send(` res.send(`
<h1>multy stub is working v${pkg.version}</h1> <h1>multy stub is working v${pkg.version}</h1>
<ul> <ul>
@@ -20,7 +19,8 @@ router.get('/', async (req, res) => {
<h2>models</h2> <h2>models</h2>
<ul>${ <ul>${
(await Promise.all( (await Promise.all(
(await mongoose.modelNames()).map(async (name) => { (
await mongoose.modelNames()).map(async (name) => {
const count = await mongoose.model(name).countDocuments() const count = await mongoose.model(name).countDocuments()
return `<li>${name} - ${count}</li>` return `<li>${name} - ${count}</li>`
} }

View File

@@ -1,12 +1,17 @@
[ [
{ {
"id": 0, "id": 0,
"description": "1000 часто используемых", "description": "10 часто используемых",
"imageFilename": "kart1.jpg" "imageFilename": "kart1.jpg"
}, },
{ {
"id": 1, "id": 1,
"description": "10 слов в Data Science", "description": "10 слов в Data Science",
"imageFilename": "kart1.jpg" "imageFilename": "kart1.jpg"
},
{
"id": 2,
"description": "IT Basics Dictionary",
"imageFilename": "kart1.jpg"
} }
] ]

View File

@@ -146,5 +146,130 @@
] ]
} }
] ]
},
{
"id": 2,
"words": [
{
"id": 0,
"word": "software",
"translation": "программное обеспечение",
"definition": "A collection of computer instructions that perform a specific task, typically for use by humans or machines.",
"synonyms": ["код", "приложение", "управление программами"],
"examples":
[
"I need to update the software on my new laptop.",
"The company uses Windows as its operating system."
]
},
{
"id": 1,
"word": "hardware",
"translation": "железо",
"definition": "Physical components of a computer that process information, including processors and storage devices.",
"synonyms": ["equipment", "приборы", "оборудование"],
"examples":
[
"The keyboard is part of the hardware on this device.",
"They upgraded their router to improve internet speed."
]
},
{
"id": 2,
"word": "network",
"translation": "сети",
"definition": "A system of interconnected devices that communicate with each other through data transmission over a networked medium.",
"synonyms": ["трансляция", "коммуникации", "диалог"],
"examples":
[
"We use the internet to connect our devices in the same area.",
"The company relies on their internal network for data sharing."
]
},
{
"id": 3,
"word": "algorithm",
"translation": "алгоритм",
"definition": "A set of instructions that a computer follows to solve a problem or achieve a specific task.",
"synonyms": ["процесс", "схема", "текст"],
"examples":
[
"The algorithm for sorting numbers is easy to follow.",
"The new software includes an advanced algorithm."
]
},
{
"id": 4,
"word": "encryption",
"translation": "криптография",
"definition": "A technique that transforms information into a secure form, making it unreadable without the appropriate key.",
"synonyms": ["шифрование", "окрышение", "опциональное"],
"examples":
[
"Our data is encrypted to ensure its privacy and security.",
"I need to use an encryption program for my important documents."
]
},
{
"id": 5,
"word": "debugging",
"translation": "поиск и исправление ошибок",
"definition": "The process of identifying and correcting errors or defects in a computer program.",
"synonyms": ["исправление", "сканирование", "анализ"],
"examples":
[
"I need to debug the code for this new project.",
"We use automated tools to find bugs."
]
},
{
"id": 6,
"word": "API",
"translation": "интерфейс приложения",
"definition": "A set of rules and protocols that enables communication between software applications, typically over a network.",
"synonyms": ["серверное программирование", "функциональная структура"],
"examples":
[
"We use the API for our mobile app to access data from the backend server.",
"I need to write an API for connecting my devices to the internet."
]
},
{
"id": 7,
"word": "virtual",
"translation": "виртуальный",
"definition": "A representation of a thing that does not exist physically but exists in digital form.",
"synonyms": ["высокопроизводительный", "представление", "цифровой"],
"examples":
[
"I use virtual reality to experience different environments.",
"Our company offers virtual office spaces for remote work."
]
},
{
"id": 8,
"word": "infrastructure",
"translation": "инфраструктура",
"definition": "The underlying systems and equipment of a computer network or organization, including hardware, software, and physical connections.",
"synonyms": ["оборудование", "устройство", "системы"],
"examples":
[
"Our IT infrastructure is robust to ensure reliable operations.",
"They need to improve their internet infrastructure for better connectivity."
]
},
{
"id": 9,
"word": "hacker",
"translation": "хакер",
"definition": "A skilled individual who uses computer technology to break into and misuse a system or network.",
"synonyms": ["дезориентированный", "манипулятор", "прокурор"],
"examples":
[
"I need to avoid getting involved with hackers.",
"They were caught hacking into the company's confidential database."
]
}
]
} }
] ]

View File

@@ -1,3 +1,5 @@
const fs = require('fs');
const path = require('path');
const router = require("express").Router(); const router = require("express").Router();
module.exports = router; module.exports = router;
@@ -9,6 +11,59 @@ router.get("/", (req, res) => {
res.send(data); res.send(data);
}); });
// Put new dictionary to the array of dictionaries
router.put('/new', (req, res) => {
if (!data || !Array.isArray(data)) {
return res.status(400).send('No array of dictionaries found`');
}
const updatedData = req.body;
if (!updatedData) {
return res.status(400).send('No data to update'); // Bad request
}
if (!data) {
return res.status(500).send('No data to update'); // Internal server error
}
indexedUpdatedData = { id: data.length, ...updatedData }; // Add the new dictionary to the array
data.push(indexedUpdatedData); // Add the new dictionary to the array
fs.writeFile(path.join(__dirname, 'data/dictionaries.json'), JSON.stringify(data), (err) => {
if (err) {
console.error(err); // Log the error
return res.status(500).send('Error saving data');
}
res.status(200).json(data); // Send back the updated data
});
});
router.delete('/:id', (req, res) => {
const id = parseInt(req.params.id); // Get the dictionary id from the URL
if (!id || isNaN(id)) {
return res.status(400).send('Invalid ID'); // Bad request
}
const index = data.findIndex((dictionary) => dictionary.id === id);
if (index < 0) {
return res.status(404).send('Not found'); // Not found
}
data.splice(index, 1); // Remove the dictionary from the array
fs.writeFile(path.join(__dirname, 'data/dictionaries.json'), JSON.stringify(data), (err) => {
if (err) {
console.error(err); // Log the error
return res.status(500).send('Error saving data');
}
res.send({ message: `Dictionary with id ${id} deleted` });
});
});
router.get("/:id", (req, res) => { router.get("/:id", (req, res) => {
const id = parseInt(req.params.id); const id = parseInt(req.params.id);
const words = wordsData.find((word) => word.id === id); const words = wordsData.find((word) => word.id === id);

View File

@@ -1,13 +1,15 @@
const router = require("express").Router(); const router = require("express").Router();
const dictionariesRouter = require("./dictionaries"); const dictionariesRouter = require("./dictionaries");
const unitsRouter = require('./units');
module.exports = router; module.exports = router;
const delay = const delay =
(ms = 1000) => (ms = 250) =>
(req, res, next) => { (req, res, next) => {
setTimeout(next, ms); setTimeout(next, ms);
}; };
router.use(delay()); router.use(delay());
router.use("/dictionaries", dictionariesRouter); router.use("/dictionaries", dictionariesRouter);
router.use('/units', unitsRouter);

View File

@@ -0,0 +1,71 @@
# Unit 1. Multifunctional Verbs: Be, Have, and Do
## Overview
This unit focuses on the use of multifunctional verbs in English. These verbs are able to express multiple meanings depending on their use in a sentence.
## Learning Objectives
By the end of this unit, you will be able to:
- Identify the different forms of the main multifunctional verb.
- Explain how these forms can be used interchangeably in sentences.
- Demonstrate the correct usage of the three forms of the multifunctional verb by providing sentences and examples.
## Vocabulary Review
| Term | Definition |
| ---- | -------------------------------------------------------- |
| Be | To express a present or ongoing state of being. |
| Have | To express ownership or possession. |
| Do | To express an action to be done, future action or habit. |
## Activities
### Activity 1: Identify the Different Forms of the Main Multifunctional Verb
- Read through each sentence and identify if the verb is used in its present tense (is), past tense (was/were), or future tense (will, would).
- Discuss how this usage can vary depending on context.
- Write down sentences that use different forms to illustrate your points.
1. **Sentence 1**: "The cat is sleeping."
- Present tense: The cat is sleeping.
- Past tense: The cat slept.
- Future tense: The cat will sleep.
2. **Sentence 2**: "I have a dog at home."
- Present tense: I have a dog.
- Past tense: I had a dog.
- Future tense: I will have a dog.
3. **Sentence 3**: "We are going on a hike tomorrow."
- Present tense: We are going on a hike.
- Past tense: We went on a hike.
- Future tense: We will go on a hike.
4. **Sentence 4**: "He has been studying all day."
- Present tense: He is studying.
- Past tense: He studied.
- Future tense: He will study.
5. **Sentence 5**: "We are going to buy some groceries later today."
- Present tense: We are going to buy some groceries.
- Past tense: We bought some groceries.
- Future tense: We will buy some groceries.
### Activity 2: Explain How These Forms Can Be Used Interchangeably in Sentences
- Read through a sentence and identify the present, past, and future tense uses.
- In pairs, explain why these forms are used interchangeably.
- Provide examples of sentences that demonstrate this usage.
- Highlight how the context changes the meaning.
### Activity 3: Correct Usage of the Three Forms of the Multifunctional Verb
- Read through a sentence and identify which form is being used.
- In pairs, discuss why these forms are used in certain situations.
- Provide sentences that demonstrate the correct usage of the three forms.

View File

@@ -0,0 +1 @@
[{"id":0,"filename":"unit-1","name":"Unit 1: Multifunctional Verbs: Be, Have, and Do"}]

View File

@@ -0,0 +1,58 @@
const fs = require('fs');
const path = require('path');
const router = require('express').Router();
module.exports = router;
const data = require('./data/units.json');
router.get('/', (req, res) => {
res.send(data);
});
router.put('/', (req, res) => {
const newUnit = req.body
if (!newUnit) {
return res.status(400).send('No new unit to be added')
}
if (!data) {
return res.status(500).send('No data to be updated')
}
data.push({ "id": data.length, ...newUnit })
fs.writeFileSync(path.join(__dirname, 'data', 'units.json'), JSON.stringify(data));
res.status(200).send(data);
});
router.delete('/:id', (req, res) => {
const id = parseInt(req.params.id);
const index = data.findIndex((unit) => unit.id === id);
if (index < 0) {
return res.status(404).send('Not found');
}
data.splice(index, 1);
fs.writeFileSync(path.join(__dirname, 'data', 'units.json'), JSON.stringify(data));
res.send({ message: `Unit with ID ${id} deleted` });
});
router.get('/:id', (req, res) => {
const id = parseInt(req.params.id);
const unit = data.find((unit) => unit.id === id);
if (!unit) {
return res.status(404).send('Not found');
}
const unitFilepath = path.join(__dirname, 'data', `${unit.filename}.md`);
const unitContent = fs.readFileSync(unitFilepath, 'utf-8');
if (!unitContent) {
return res.status(404).send('Not found');
}
res.send({ ...unit, content: unitContent });
});