-
Notifications
You must be signed in to change notification settings - Fork 0
Добавить новый пользовательский функционал #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Zamelane
wants to merge
18
commits into
notifications-tg
Choose a base branch
from
new-user-functional
base: notifications-tg
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
997ab12
Набросать редактирование пользователя
Zamelane f41f142
WIP
Zamelane afefdc1
Изменения перед миграцией
Zamelane 5e360f2
Обновить @vkontakte/vkui до 7.0.0
Zamelane 6c42a97
Добавить принудительное редактирование схемы таблиц
Zamelane 4d70249
Добавить аккуратно редактирование схемы таблиц
Zamelane c0164dc
fix: a bit UI fixes
scffs 81cd390
fix: a bit UI fixes
scffs 907baa1
WIP
Kopchan aa4f2bd
Заготовка магазина и рабочие фильтры
Zamelane 2a0c89b
Заготовка магазина и рабочие фильтры
Zamelane b394b6c
Подготовка магазина
Zamelane 55687c6
lint
scffs 00ee886
deps
scffs 6eb427f
WIP
Zamelane 38ca018
WIP
Zamelane b76ddea
WIP
Zamelane dedaf0a
WIP
Zamelane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,5 @@ package-lock.json | |
# IDE files | ||
/.idea | ||
|
||
#uploads | ||
src/uploads/avatars |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const crutchesInit = () => { | ||
// @ts-ignore | ||
BigInt.prototype.toJSON = function() { return this.toString() } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { readdir } from 'node:fs/promises' | ||
import cliProgress from 'cli-progress' | ||
import { AvatarModel } from '../models/Avatar' | ||
import { AvatarTagModel } from '../models/AvatarTag' | ||
import { TagModel } from '../models/Tag' | ||
|
||
const pathToDecorationsFile = 'src/uploads/decorations.json' | ||
const pathToAvatars = 'src/uploads/avatars' | ||
|
||
interface Content { | ||
avatars: AvatarContent[] | ||
} | ||
|
||
interface AvatarContent { | ||
isAnimated: boolean | ||
filename: string | ||
tags: string[] | ||
price: number | ||
} | ||
|
||
export const syncDatabaseForDecorations = async () => { | ||
console.log('Обновляю декорации в базе данных...') | ||
|
||
const progress = 0 | ||
const progressBar = new cliProgress.SingleBar( | ||
{ | ||
format: ' {bar} | {filename} | {value}/{total}' | ||
}, | ||
cliProgress.Presets.shades_classic | ||
) | ||
|
||
const file = Bun.file(pathToDecorationsFile) | ||
|
||
if (!(await file.exists())) { | ||
console.log('Файл декораций не найден. Пропускаю ...') | ||
return | ||
} | ||
|
||
const contents: Content = await file.json() | ||
const avatarFiles = await readdir(pathToAvatars) | ||
|
||
progressBar.start(avatarFiles.length, progress) | ||
|
||
for (const avatarFile of avatarFiles) { | ||
progressBar.increment(1, { filename: avatarFile }) | ||
const avatarToSave = { | ||
filename: avatarFile, | ||
isAnimated: avatarFile.endsWith('.gif'), | ||
price: 1000 | ||
} | ||
|
||
let tags: string[] = [] | ||
|
||
// Пробуем найти, переопределена ли цена и статус анимации | ||
for (const avatarInfo of contents.avatars) { | ||
if (avatarInfo.filename !== avatarFile) continue | ||
avatarToSave.isAnimated = avatarInfo.isAnimated | ||
avatarToSave.price = avatarInfo.price | ||
tags = avatarInfo.tags | ||
break | ||
} | ||
|
||
// Находим или создаём модель | ||
const avatarModel = await AvatarModel.findOrCreate({ | ||
where: { | ||
filename: avatarFile | ||
}, | ||
defaults: avatarToSave | ||
}) | ||
|
||
// Проверяем наличие тегов | ||
if (!tags) | ||
await AvatarTagModel.destroy({ | ||
where: { | ||
avatarId: avatarModel[0].id | ||
} | ||
}) | ||
else | ||
for (const tag of tags) { | ||
const tagModel = await TagModel.findOrCreate({ | ||
where: { | ||
value: tag | ||
}, | ||
defaults: { | ||
value: tag | ||
} | ||
}) | ||
await AvatarTagModel.findOrCreate({ | ||
where: { | ||
avatarId: avatarModel[0].id, | ||
tagId: tagModel[0].id | ||
}, | ||
defaults: { | ||
avatarId: avatarModel[0].id, | ||
tagId: tagModel[0].id | ||
} | ||
}) | ||
} | ||
|
||
// Если создана - то завершаем цикл | ||
if (avatarModel[1]) continue | ||
|
||
await avatarModel[0].update(avatarToSave) | ||
} | ||
|
||
progressBar.stop() | ||
|
||
console.log('Обновил все декорации') | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DataTypes } from 'sequelize' | ||
|
||
import { cache, enableCache, sequelize } from '@db' | ||
|
||
import { SPOModel } from '../SPO' | ||
import type { IModelPrototype } from '../types' | ||
|
||
// REMOVE IT | ||
// ? | ||
export type AvatarModelType = { | ||
id: number | ||
filename: string | ||
price: number | ||
isAnimated: boolean | ||
} | ||
|
||
export type IAvatarModelType = IModelPrototype<AvatarModelType, 'id'> | ||
|
||
const avatarModel = sequelize.define<IAvatarModelType>('avatar', { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true | ||
}, | ||
filename: { | ||
type: DataTypes.STRING(35), | ||
allowNull: false | ||
}, | ||
price: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
defaultValue: 1000 | ||
}, | ||
isAnimated: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false | ||
} | ||
}) | ||
|
||
export const AvatarModel = enableCache | ||
? cache.init<IAvatarModelType>(avatarModel) | ||
: avatarModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DataTypes } from 'sequelize' | ||
|
||
import { cache, enableCache, sequelize } from '@db' | ||
|
||
import { AvatarModel } from '../Avatar' | ||
import { TagModel } from '../Tag' | ||
import type { IModelPrototypeNoId } from '../types' | ||
|
||
// REMOVE IT | ||
// ? | ||
export type AvatarTagModelType = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вынести в shared, если ещё не там (если есть необходимость использовать на фронте) |
||
avatarId: bigint | ||
tagId: bigint | ||
} | ||
|
||
export type IAvatarTagModelType = IModelPrototypeNoId<AvatarTagModelType> | ||
|
||
const avatarTagModel = sequelize.define<IAvatarTagModelType>('avatarTag', { | ||
avatarId: { | ||
type: DataTypes.BIGINT, | ||
primaryKey: true, | ||
allowNull: false, | ||
references: { | ||
model: AvatarModel | ||
} | ||
}, | ||
tagId: { | ||
type: DataTypes.BIGINT, | ||
primaryKey: true, | ||
allowNull: false, | ||
references: { | ||
model: TagModel | ||
} | ||
} | ||
}) | ||
|
||
export const AvatarTagModel = enableCache | ||
? cache.init<IAvatarTagModelType>(avatarTagModel) | ||
: avatarTagModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { DataTypes } from 'sequelize' | ||
|
||
import { cache, enableCache, sequelize } from '@db' | ||
|
||
import type {IModelPrototype} from '../types' | ||
import {Nullable} from "@diary-spo/shared"; | ||
import {DiaryUserModel} from "../DiaryUser"; | ||
|
||
export type BalanceOperationModelType = { | ||
id: bigint | ||
diaryUserId: bigint | ||
senderId: Nullable<bigint> | ||
comment: Nullable<string> | ||
amount: number | ||
datetime?: string | ||
} | ||
|
||
export type IBalanceOperationModelType = IModelPrototype<BalanceOperationModelType, 'id'> | ||
|
||
const balanceOperationModel = sequelize.define<IBalanceOperationModelType>('balanceOperation', { | ||
id: { | ||
type: DataTypes.BIGINT, | ||
primaryKey: true, | ||
autoIncrement: true | ||
}, | ||
senderId: { | ||
type: DataTypes.BIGINT, | ||
allowNull: true, | ||
references: { | ||
model: DiaryUserModel | ||
} | ||
}, | ||
diaryUserId: { | ||
type: DataTypes.BIGINT, | ||
references: { | ||
model: DiaryUserModel | ||
} | ||
}, | ||
comment: { | ||
type: DataTypes.STRING, | ||
allowNull: true | ||
}, | ||
amount: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
datetime: { | ||
type: DataTypes.DATEONLY, | ||
allowNull: false, | ||
defaultValue: Date.now() | ||
} | ||
}) | ||
|
||
export const BalanceOperationModel = enableCache | ||
? cache.init<IBalanceOperationModelType>(balanceOperationModel) | ||
: balanceOperationModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { DataTypes } from 'sequelize' | ||
|
||
import { cache, enableCache, sequelize } from '@db' | ||
|
||
import type { IModelPrototype } from '../types' | ||
|
||
// REMOVE IT | ||
// ? | ||
export type TagModelType = { | ||
id: bigint | ||
value: string | ||
} | ||
|
||
export type ITagModelType = IModelPrototype<TagModelType, 'id'> | ||
|
||
const tagModel = sequelize.define<ITagModelType>('tag', { | ||
id: { | ||
type: DataTypes.BIGINT, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
allowNull: false | ||
}, | ||
value: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
} | ||
}) | ||
|
||
export const TagModel = enableCache | ||
? cache.init<ITagModelType>(tagModel) | ||
: tagModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './model' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
уже есть такой тип в shared