Compare commits

..

No commits in common. "master" and "v1.2.0" have entirely different histories.

15 changed files with 11 additions and 7736 deletions

2
.npmrc
View File

@ -1 +1 @@
package-lock=true
package-lock=false

View File

@ -1,6 +1,6 @@
#!/bin/sh
docker stop $(docker ps -q)
docker volume remove red_coder_volume
docker volume create red_coder_volume
docker run --rm -v red_coder_volume:/data/db -p 27017:27017 -d mongo:4.4.13
docker volume remove multy_stub_volume
docker volume create multy_stub_volume
docker run --rm -v multy_stub_volume:/data/db -p 27017:27017 -d mongo

View File

@ -5,7 +5,7 @@ volumes:
services:
mongoDb:
image: mongo:4.4.13
image: mongo:5.0.7
volumes:
- red-coder_volume:/data/db
restart: always

7571
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{
"name": "red-coder-bh",
"version": "1.3.3",
"version": "1.2.0",
"description": "",
"main": "src/main.ts",
"scripts": {
"start": "cross-env MODE=\"dev\" nodemon",
"start": "nodemon",
"build": "tsc",
"up:prod": "node dist/src/main",
"up:prod": "node dist/main",
"deploy:d:stop": "docker-compose down",
"deploy:d:build": "docker-compose build",
"deploy:d:up": "docker-compose up -d",
@ -31,7 +31,6 @@
"@types/cookie-session": "^2.0.44",
"axios": "^0.26.1",
"cookie-session": "^2.0.0",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dotenv": "^16.0.0",
"express": "^4.17.3",

View File

@ -1,5 +1,2 @@
export const usersCollection = 'USERS_COLLECTIONS'
export const draftsCollection = 'DRAFTS_CLLECTION'
export const tasksCollection = 'TASKS_CLLECTION'
export const numberCollection = 'NUMBER_COLLECTION'

View File

@ -13,6 +13,6 @@ init({
})
if (process.env.MAIL_TO_1 && process.env.MODE !== 'dev') {
addToQueue(new AdminNotificationRequest(`Деплой RED-CODER-BH v${pkg.version} прошёл успешно`))
addToQueue(new AdminNotificationRequest(`Деплой админки v${pkg.version} прошёл успешно`))
}

View File

@ -1,11 +1,9 @@
import express from 'express'
import cookieSession from 'cookie-session'
import cors from 'cors'
import './config'
import { errorHandle } from './utils/error-handling'
import { router } from './routes'
import './mailer'
const app = express()
@ -14,7 +12,6 @@ const port = process.env.RED_CODER_BH_PORT
app.use(express.json())
app.use(cookieSession({ secret: process.env.COOKIE_SESSION }))
app.use(cors('*'))
app.use(router)
app.use(errorHandle)

View File

@ -1,56 +1,9 @@
import { Router } from 'express'
import expressjwt from 'express-jwt'
import { authRouter } from './v1/auth'
import { bannerRouter } from './v1/banner'
import tasksRouter from './v1/tasks'
import draftsRouter from './v1/drafts'
export const router = Router()
const jwtMiddlevare = expressjwt({
secret: process.env.JWT_SECRET_STRING,
algorithms: ['HS256']
})
router.use(bannerRouter)
router.use('/v1/auth', authRouter)
router.use(['/v1/tasks', '/v1/task'], jwtMiddlevare, tasksRouter)
router.use('/v1/drafts', jwtMiddlevare, draftsRouter)
const charLikes = {}
router.get('/likes', (req, res) => {
res.set({
'Access-Control-Allow-Origin': 'http://admin.inno-js.ru',
})
res.send({
likes: charLikes,
})
})
router.post('/toggle-like', (req, res) => {
const { id, charId } = req.body
if (charLikes[charId]) {
const currentLikes = new Set(charLikes[charId].likes)
if (currentLikes.has(id)) {
currentLikes.delete(id)
} else {
currentLikes.add(id)
}
charLikes[charId].likes = [...currentLikes]
} else {
charLikes[charId] = { likes: [id] }
}
res.set({
'Access-Control-Allow-Origin': 'http://admin.inno-js.ru',
})
res.send({
likes: charLikes,
})
})

View File

@ -3,7 +3,6 @@ import { Db } from 'mongodb'
import { mainDb } from '../../utils/mongo'
import { cleanId } from '../../utils/common'
import { usersCollection } from '../../__data__/constants'
import { Roles } from '../../model/roles'
export const registerUser = async ({ username, regtime, role, email, id, ...rest }) => {
const db: Db = await mainDb
@ -12,7 +11,6 @@ export const registerUser = async ({ username, regtime, role, email, id, ...rest
const [registred] = await usersCl.find({ ijlId: id }).toArray()
const user = {
role: Roles.User,
...(registred || {}),
ijlId: id,
ijlUser: {

View File

@ -1,15 +0,0 @@
import { Router } from 'express'
import { getAnswer } from '../../utils/common'
import { requiredFields } from '../../utils/required'
import { getDrafts } from './tasks.controller'
const router = Router()
router.get('/', async (req, res) => {
const drafts = await getDrafts((req as any)?.user?.id)
res.send(getAnswer(null, drafts))
})
export default router

View File

@ -1,62 +0,0 @@
import { Db, ObjectId } from 'mongodb'
import { mainDb } from '../../utils/mongo'
import { cleanId } from '../../utils/common'
import { draftsCollection, tasksCollection, numberCollection } from '../../__data__/constants'
export const createTask = async ({ userId }) => {
const db: Db = await mainDb
const col = db.collection(draftsCollection)
const ncol = db.collection(numberCollection)
const numberObject = await ncol.findOne({})
if (!numberObject) {
await ncol.insertOne({ number: 1 })
}
ncol.updateOne({}, {
$set: {
number: (numberObject?.number || 1) + 1
}
})
const draftTask = {
cratedBy: new ObjectId(userId),
createdDt: Date.now(),
lastModufy: Date.now(),
names: {
'ru': 'Полиндром'
},
'draft': true,
'number': (numberObject?.number || 1) + 1,
'markdown': '# Напишите функцию проверки текста на полиндром\\n## Напишите функцию проверки текста на полиндром\\n### Напишите функцию проверки текста на полиндром\\n#### Напишите функцию проверки текста на полиндром\\n##### Напишите функцию проверки текста на полиндром\\n###### Напишите функцию проверки текста на полиндром\\n\\nБлок текста с описанием задачи.\\n[Ссылка](https://reactjs.org/) на документацию реакта\\n\\nНе забудьте [зарегистрироваться](/auth) и [поискать](/main) задачки\\n\\n![react logo](https://tproger.ru/s3/uploads/2016/10/reactmini.png)\\n\\n![line](https://www.clipartmax.com/png/small/44-446497_lines-clipart-vertical-line-blue-vertical-line-png.png)\\n\\n> цитата\\n> цитата\\n> цитата\\n\\n```javascript\\nimport { useCallback, useRef, useEffect } from \'react\';\\nimport { editor as mEditor } from \'monaco-editor\';\\n\\nexport const useMonako = (inputData, remountFlag, language: string, onChange = (value: string) => null) => {\\n const editorRef = useRef<mEditor.IStandaloneCodeEditor>();\\n const nodeRef = useRef(null);\\n const remount = useCallback(() => {\\n editorRef.current?.dispose();\\n editorRef.current = mEditor.create(nodeRef.current, {\\n value: inputData,\\n theme: \'light\' === \'light\' ? \'vs\' : \'vs-dark\',\\n language,\\n });\\n\\n const model = editorRef.current.getModel();\\n model.onDidChangeContent(() => {\\n const value = model.getValue();\\n onChange(value)\\n });\\n } ,[inputData, nodeRef]);\\n\\n useEffect(() => {\\n try {\\n setTimeout(() => {\\n if (nodeRef.current) {\\n remount();\\n\\n () => {\\n editorRef.current.dispose();\\n editorRef.current = null;\\n };\\n }\\n }, 2);\\n } catch (error) {\\n console.error(error);\\n }\\n }, [nodeRef, remountFlag]);\\n\\n return {\\n nodeRef,\\n getValue: () => editorRef?.current?.getValue(),\\n };\\n}\\n\\n```'
}
await col.insertOne(draftTask)
return cleanId(draftTask)
}
export const getTaskData = async (taskId) => {
const db: Db = await mainDb
const col = db.collection(draftsCollection)
const task = await col.findOne({
_id: new ObjectId(taskId),
}).catch(console.log)
return cleanId(task)
}
export const getDrafts = async (userId) => {
const db: Db = await mainDb
const col = db.collection(draftsCollection)
const tasks = await col.find({
cratedBy: new ObjectId(userId),
}).toArray()
return cleanId(tasks)
}

View File

@ -1,21 +0,0 @@
import { Router } from 'express'
import { requiredFields } from '../../utils/required'
import { createTask, getTaskData } from './tasks.controller'
const router = Router()
router.post('/create', async (req, res) => {
const draft = await createTask({ userId: (req as any)?.user?.id })
res.send(draft)
})
router.post('/data', requiredFields(['id']), async (req, res) => {
const { id } = req.body
const task = await getTaskData(id)
res.send(task)
})
export default router

View File

@ -1,7 +1,7 @@
import baseAxios from 'axios'
export const adminAxios = baseAxios.create({
baseURL: `http://${process.env.ADMIN_SERVER_BASE_NAME}/api/out/v2`,
baseURL: `http://${process.env.ADMIN_SERVER_BASE_NAME}/api/out`,
method: 'POST',
})

View File

@ -2,7 +2,7 @@ const getAnswer = (errors, data, success = true) => {
if (errors) {
return { success: false, errors }
} else {
return { success, data }
return { success, body: data }
}
}