Initial commit: Tapalka monorepo (bot, front, strapi)

This commit is contained in:
2026-05-21 11:54:44 +07:00
commit 9ec9485940
208 changed files with 58314 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
HOST=0.0.0.0
PORT=1337
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified
JWT_SECRET=tobemodified
DATABASE_CLIENT=sqlite
DATABASE_NAME=robucks
DATABASE_FILENAME=./data/database.db
BOT_URL=http://127.0.0.1:3001

View File

@@ -0,0 +1,7 @@
HOST=0.0.0.0
PORT=1337
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified
JWT_SECRET=tobemodified

View File

@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": ["warn", {
"endOfLine": "auto",
"semi": true,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "all",
"useTabs": false,
"tabWidth": 4,
"jsxSingleQuote": true,
"bracketSpacing": true,
"arrowParens": "avoid"
}
],
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-explicit-any": "off",
"prefer-const": "warn",
"no-console": "warn"
}
}

View File

@@ -0,0 +1,27 @@
name: Deploy to prod
on:
workflow_dispatch:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy with pm2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{secrets.PROD_SSH_HOST}}
username: ${{secrets.PROD_SSH_USERNAME}}
password: ${{secrets.PROD_SSH_PASSWORD}}
script_stop: true
script: |
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh # активирует npm на нашем сервере
cd ${{secrets.PROD_PROJECT_PATH}}
git checkout main
git pull
yarn install
pm2 restart ecosystem.config.js

116
CMyTapper/robucks-strapi/.gitignore vendored Normal file
View File

@@ -0,0 +1,116 @@
############################
# OS X
############################
.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*
############################
# Linux
############################
*~
############################
# Windows
############################
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp
############################
# Packages
############################
*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid
############################
# Logs and databases
############################
.tmp
*.log
*.sql
*.sqlite
*.sqlite3
############################
# Misc.
############################
*#
ssl
.idea
nbproject
public/uploads/*
!public/uploads/.gitkeep
############################
# Node.js
############################
lib-cov
lcov.info
pids
logs
results
node_modules
.node_history
############################
# Tests
############################
coverage
############################
# Strapi
############################
.env
license.txt
exports
.strapi
dist
build
.strapi-updater.json
.strapi-cloud.json
.idea

View File

@@ -0,0 +1,2 @@
overrides:
@strapi/plugin-upload: false

View File

@@ -0,0 +1,57 @@
# 🚀 Getting started with Strapi
Strapi comes with a full featured [Command Line Interface](https://docs.strapi.io/dev-docs/cli) (CLI) which lets you scaffold and manage your project in seconds.
### `develop`
Start your Strapi application with autoReload enabled. [Learn more](https://docs.strapi.io/dev-docs/cli#strapi-develop)
```
npm run develop
# or
yarn develop
```
### `start`
Start your Strapi application with autoReload disabled. [Learn more](https://docs.strapi.io/dev-docs/cli#strapi-start)
```
npm run start
# or
yarn start
```
### `build`
Build your admin panel. [Learn more](https://docs.strapi.io/dev-docs/cli#strapi-build)
```
npm run build
# or
yarn build
```
## ⚙️ Deployment
Strapi gives you many possible deployment options for your project including [Strapi Cloud](https://cloud.strapi.io). Browse the [deployment section of the documentation](https://docs.strapi.io/dev-docs/deployment) to find the best solution for your use case.
## 📚 Learn more
- [Resource center](https://strapi.io/resource-center) - Strapi resource center.
- [Strapi documentation](https://docs.strapi.io) - Official Strapi documentation.
- [Strapi tutorials](https://strapi.io/tutorials) - List of tutorials made by the core team and the community.
- [Strapi blog](https://strapi.io/blog) - Official Strapi blog containing articles made by the Strapi team and the community.
- [Changelog](https://strapi.io/changelog) - Find out about the Strapi product updates, new features and general improvements.
Feel free to check out the [Strapi GitHub repository](https://github.com/strapi/strapi). Your feedback and contributions are welcome!
## ✨ Community
- [Discord](https://discord.strapi.io) - Come chat with the Strapi community including the core team.
- [Forum](https://forum.strapi.io/) - Place to discuss, ask questions and find answers, show your Strapi project and get feedback or just talk with other Community members.
- [Awesome Strapi](https://github.com/strapi/awesome-strapi) - A curated list of awesome things related to Strapi.
---
<sub>🤫 Psst! [Strapi is hiring](https://strapi.io/careers).</sub>

View File

@@ -0,0 +1,17 @@
export default ({ env }) => ({
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
apiToken: {
salt: env('API_TOKEN_SALT'),
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT'),
},
},
flags: {
nps: env.bool('FLAG_NPS', true),
promoteEE: env.bool('FLAG_PROMOTE_EE', true),
},
});

View File

@@ -0,0 +1,7 @@
export default {
rest: {
defaultLimit: 55,
maxLimit: 100,
withCount: true,
},
};

View File

@@ -0,0 +1,84 @@
import path from 'path';
export default ({ env }) => {
const client = env('DATABASE_CLIENT', 'sqlite');
const connections = {
mysql: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
mysql2: {
connection: {
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
sqlite: {
connection: {
filename: path.join(
__dirname,
'..',
'..',
env('DATABASE_FILENAME', '.tmp/data.db'),
),
},
useNullAsDefault: true,
},
};
return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
},
};
};

View File

@@ -0,0 +1,12 @@
export default [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];

View File

@@ -0,0 +1,7 @@
module.exports = {
// ...
upload: {
enabled: false,
},
// ...
};

View File

@@ -0,0 +1 @@
export default () => ({});

View File

@@ -0,0 +1,10 @@
export default ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
webhooks: {
populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', false),
},
});

Binary file not shown.

View File

@@ -0,0 +1,10 @@
module.exports = {
apps: [
{
name: 'strapi',
script: 'npm run build && npm run start',
time: true,
log_date_format: 'DD.MM.YYYY HH:mm:ss',
},
],
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

22726
CMyTapper/robucks-strapi/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
{
"name": "clicker-back",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"dev": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi",
"deploy": "strapi deploy"
},
"devDependencies": {
"@strapi/strapi": "^4.26.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "8",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3"
},
"dependencies": {
"@strapi/plugin-cloud": "4.25.1",
"@strapi/plugin-i18n": "4.25.1",
"@strapi/plugin-users-permissions": "4.25.1",
"@strapi/types": "^5.36.0",
"@strapi/typescript-utils": "^5.36.0",
"@types/axios": "^0.14.0",
"axios": "^1.7.2",
"better-sqlite3": "^12.6.2",
"pg": "^8.12.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "5.3.4",
"styled-components": "5.3.3"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "fd628b0c-4d38-49d0-b9b9-ad17224f7e42"
},
"engines": {
"node": ">=18.0.0 <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}

14503
CMyTapper/robucks-strapi/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
# To prevent search engines from seeing the site altogether, uncomment the next two lines:
# User-Agent: *
# Disallow: /

View File

@@ -0,0 +1,35 @@
export default {
config: {
locales: [
// 'ar',
// 'fr',
// 'cs',
// 'de',
// 'dk',
// 'es',
// 'he',
// 'id',
// 'it',
// 'ja',
// 'ko',
// 'ms',
// 'nl',
// 'no',
// 'pl',
// 'pt-BR',
// 'pt',
// 'ru',
// 'sk',
// 'sv',
// 'th',
// 'tr',
// 'uk',
// 'vi',
// 'zh-Hans',
// 'zh',
],
},
bootstrap(app) {
console.log(app);
},
};

View File

@@ -0,0 +1,13 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/admin",
"include": [
"../plugins/**/admin/src/**/*",
"./"
],
"exclude": [
"node_modules/",
"build/",
"dist/",
"**/*.test.ts"
]
}

View File

@@ -0,0 +1,9 @@
'use strict';
/* eslint-disable no-unused-vars */
module.exports = (config, webpack) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
return config;
};

View File

@@ -0,0 +1,34 @@
{
"kind": "collectionType",
"collectionName": "archive_requests",
"info": {
"singularName": "archive-request",
"pluralName": "archive-requests",
"displayName": "ArchiveRequest",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"rejected_requests": {
"type": "relation",
"relation": "oneToMany",
"target": "api::exchange-request.exchange-request",
"mappedBy": "archive_request_rejected"
},
"exchange_requests": {
"type": "relation",
"relation": "oneToMany",
"target": "api::exchange-request.exchange-request",
"mappedBy": "archive_request_exchange"
},
"player": {
"type": "relation",
"relation": "oneToOne",
"target": "api::player.player",
"mappedBy": "archive_request"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* archive-request controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::archive-request.archive-request');

View File

@@ -0,0 +1,7 @@
/**
* archive-request router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::archive-request.archive-request');

View File

@@ -0,0 +1,7 @@
/**
* archive-request service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::archive-request.archive-request');

View File

@@ -0,0 +1,11 @@
import axios from 'axios';
export default {
async afterUpdate(event) {
const httpInstance = axios.create({
baseURL: process.env.BOT_URL
});
return await httpInstance.post('/restart-bot', {});
}
};

View File

@@ -0,0 +1,19 @@
{
"kind": "singleType",
"collectionName": "bot_configs",
"info": {
"singularName": "bot-config",
"pluralName": "bot-configs",
"displayName": "BotConfig",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"token": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* bot-config controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::bot-config.bot-config');

View File

@@ -0,0 +1,7 @@
/**
* bot-config router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::bot-config.bot-config');

View File

@@ -0,0 +1,7 @@
/**
* bot-config service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::bot-config.bot-config');

View File

@@ -0,0 +1,33 @@
{
"kind": "singleType",
"collectionName": "configs",
"info": {
"singularName": "config",
"pluralName": "configs",
"displayName": "Config",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"farm_amount": {
"type": "float"
},
"farming_time": {
"type": "integer"
},
"admins": {
"type": "relation",
"relation": "oneToMany",
"target": "api::player.player"
},
"token": {
"type": "string"
},
"dateLifetimeJwt": {
"type": "date"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* config controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::config.config');

View File

@@ -0,0 +1,7 @@
/**
* config router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::config.config');

View File

@@ -0,0 +1,7 @@
/**
* config service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::config.config');

View File

@@ -0,0 +1,63 @@
export default {
async afterUpdate(event) {
const exchangeRequest = await strapi.entityService.findOne(
'api::exchange-request.exchange-request',
event.params.where.id,
{
populate: {
archive_request_exchange: {
populate: {
player: {
populate: {
archive_request: {
populate: {
rejected_requests: true,
exchange_requests: true,
},
},
},
},
},
},
},
},
);
if (
event.params.data.status === 'rejected' &&
!exchangeRequest.archive_request_exchange.player.archive_request.rejected_requests.find(
req => req.id === event.params.data.id,
)
) {
const player = await strapi.db.query('api::player.player').update({
where: {
id: exchangeRequest.archive_request_exchange.player.id,
},
data: {
balance:
exchangeRequest.archive_request_exchange.player.balance +
event.params.data.amount,
},
populate: {
archive_request: true,
},
});
await strapi.db.query('api::archive-request.archive-request').update({
where: {
id: player.archive_request.id,
},
data: {
rejected_requests: [
...exchangeRequest.archive_request_exchange.player.archive_request
.rejected_requests,
{ id: exchangeRequest.id },
],
exchange_requests:
exchangeRequest.archive_request_exchange.player.archive_request.exchange_requests.filter(
val => val.id !== event.params.data.id,
),
},
});
}
},
};

View File

@@ -0,0 +1,51 @@
{
"kind": "collectionType",
"collectionName": "exchange_requests",
"info": {
"singularName": "exchange-request",
"pluralName": "exchange-requests",
"displayName": "ExchangeRequest",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"amount": {
"type": "float"
},
"total": {
"type": "float"
},
"roblox_nick": {
"type": "string",
"required": true
},
"status": {
"type": "enumeration",
"enum": [
"done",
"rejected",
"pending"
]
},
"archive_request_rejected": {
"type": "relation",
"relation": "manyToOne",
"target": "api::archive-request.archive-request",
"inversedBy": "rejected_requests"
},
"archive_request_exchange": {
"type": "relation",
"relation": "manyToOne",
"target": "api::archive-request.archive-request",
"inversedBy": "exchange_requests"
},
"shop_item": {
"type": "relation",
"relation": "oneToOne",
"target": "api::shop-item.shop-item"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* exchange-request controller
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreController('api::exchange-request.exchange-request');

View File

@@ -0,0 +1,7 @@
/**
* exchange-request router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::exchange-request.exchange-request');

View File

@@ -0,0 +1,7 @@
/**
* exchange-request service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::exchange-request.exchange-request');

View File

@@ -0,0 +1,27 @@
{
"kind": "collectionType",
"collectionName": "finished_tasks",
"info": {
"singularName": "finished-task",
"pluralName": "finished-tasks",
"displayName": "FinishedTask"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"status": {
"type": "enumeration",
"enum": [
"pending_prize",
"claimed"
]
},
"task": {
"type": "relation",
"relation": "oneToOne",
"target": "api::task.task"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* finished-task controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::finished-task.finished-task');

View File

@@ -0,0 +1,7 @@
/**
* finished-task router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::finished-task.finished-task');

View File

@@ -0,0 +1,7 @@
/**
* finished-task service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::finished-task.finished-task');

View File

@@ -0,0 +1,61 @@
import { toFixed } from '../../../../../utils/formatters';
export default {
async afterUpdate(event) {
const updatedPlayer = await strapi.entityService.findOne(
'api::player.player',
event.params.where.id,
);
const playerId = updatedPlayer.id;
const earned = updatedPlayer.balance - updatedPlayer.old_balance;
if (earned === 0) {
return;
}
const newBalance = toFixed(updatedPlayer.balance);
await strapi.entityService.update('api::player.player', playerId, {
data: {
balance: newBalance,
old_balance: newBalance,
} as any,
});
if (earned < 0) {
return;
}
const player = await strapi.entityService.findOne('api::player.player', playerId, {
populate: {
referral: true,
},
});
let referralDepthLevel = 0;
let referral = player.referral;
while (referral) {
referralDepthLevel += 1;
const multiplier =
referralDepthLevel <= 1 ? 0.1 : referralDepthLevel === 2 ? 0.05 : 0.025;
const fee = toFixed(earned * multiplier);
const updatedReferral = await strapi.entityService.update(
'api::player.player',
referral.id,
{
data: {
balance: referral.balance + fee,
old_balance: referral.old_balance + fee,
referral_fee: referral.referral_fee + fee,
} as any,
populate: {
referral: true,
},
},
);
referral = updatedReferral.referral;
}
},
};

View File

@@ -0,0 +1,64 @@
{
"kind": "collectionType",
"collectionName": "players",
"info": {
"singularName": "player",
"pluralName": "players",
"displayName": "Player",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"telegram_nick": {
"type": "string",
"required": true
},
"telegram_id": {
"type": "string",
"required": true
},
"balance": {
"type": "float"
},
"my_referrals": {
"type": "relation",
"relation": "oneToMany",
"target": "api::player.player",
"mappedBy": "referral"
},
"referral": {
"type": "relation",
"relation": "manyToOne",
"target": "api::player.player",
"inversedBy": "my_referrals"
},
"start_farm": {
"type": "datetime"
},
"finished_tasks": {
"type": "relation",
"relation": "oneToMany",
"target": "api::finished-task.finished-task"
},
"archive_request": {
"type": "relation",
"relation": "oneToOne",
"target": "api::archive-request.archive-request",
"inversedBy": "player"
},
"old_balance": {
"type": "float"
},
"referral_fee": {
"type": "decimal",
"min": 0,
"default": 0
},
"auth_id": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,13 @@
/**
* player controller
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreController('api::player.player', ({ strapi }) => ({
async updateFinishedTasks(ctx) {
const { id } = ctx.params;
const data = (ctx.request as any).body;
return await strapi.service('api::player.player').updateFinishedTasks(+id, data);
},
}));

View File

@@ -0,0 +1,7 @@
/**
* player router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::player.player');

View File

@@ -0,0 +1,13 @@
export default {
routes: [
{
method: 'PUT',
path: '/players/finished-tasks/:id',
handler: 'player.updateFinishedTasks',
config: {
policies: [],
middlewares: [],
},
},
],
};

View File

@@ -0,0 +1,71 @@
/**
* player service
*/
import { factories } from '@strapi/strapi';
import { toFixed } from '../../../../utils/formatters';
export default factories.createCoreService('api::player.player', ({ strapi }) => ({
async updateFinishedTasks(
id: number,
data: { taskId: number; status: 'pending_prize' | 'claimed' },
) {
const player = await strapi.entityService.findOne('api::player.player', id, {
populate: {
finished_tasks: {
populate: {
task: true,
},
},
},
});
const task = await strapi.entityService.findOne('api::task.task', data.taskId);
const finishedTask = player.finished_tasks.find(
finishedTask => finishedTask.task.id === task.id,
);
if (!finishedTask) {
const newFinishedTask = await strapi.entityService.create(
'api::finished-task.finished-task',
{
data: {
status: data.status,
task: {
id: task.id,
},
},
},
);
const { id: updatedPlayerId, ...rest } = await strapi.entityService.update(
'api::player.player',
player.id,
{
data: {
finished_tasks: {
connect: [newFinishedTask.id],
},
} as any,
},
);
return { id: updatedPlayerId, attributes: rest };
}
await strapi.entityService.update('api::finished-task.finished-task', finishedTask.id, {
data: {
status: data.status,
} as any,
});
const { id: updatedPlayerId, ...rest } = await strapi.entityService.update(
'api::player.player',
player.id,
{
data: {
balance: toFixed(player.balance + task.prize),
} as any,
},
);
return { id: updatedPlayerId, attributes: rest };
},
}));

View File

@@ -0,0 +1,34 @@
{
"kind": "collectionType",
"collectionName": "shop_items",
"info": {
"singularName": "shop-item",
"pluralName": "shop-items",
"displayName": "ShopItem",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"name": {
"type": "string"
},
"price": {
"type": "decimal"
},
"icon": {
"type": "media",
"multiple": false,
"required": true,
"allowedTypes": [
"images"
]
},
"isDecimal": {
"type": "boolean",
"default": false
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* shop-item controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::shop-item.shop-item');

View File

@@ -0,0 +1,7 @@
/**
* shop-item router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::shop-item.shop-item');

View File

@@ -0,0 +1,7 @@
/**
* shop-item service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::shop-item.shop-item');

View File

@@ -0,0 +1,38 @@
{
"kind": "collectionType",
"collectionName": "tasks",
"info": {
"singularName": "task",
"pluralName": "tasks",
"displayName": "Task",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"title": {
"type": "string",
"required": true
},
"link": {
"type": "string",
"required": true
},
"icon": {
"type": "media",
"multiple": false,
"required": false,
"allowedTypes": [
"images",
"files",
"videos",
"audios"
]
},
"prize": {
"type": "float"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* task controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::task.task');

View File

@@ -0,0 +1,7 @@
/**
* task router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::task.task');

View File

@@ -0,0 +1,7 @@
/**
* task service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::task.task');

View File

@@ -0,0 +1,22 @@
{
"collectionName": "components_finished_tasks_finshed_tasks",
"info": {
"displayName": "finshed_tasks",
"description": ""
},
"options": {},
"attributes": {
"status": {
"type": "enumeration",
"enum": [
"pending_prize",
"claimed"
]
},
"task": {
"type": "relation",
"relation": "oneToOne",
"target": "api::task.task"
}
}
}

View File

@@ -0,0 +1,69 @@
{
"kind": "collectionType",
"collectionName": "up_users",
"info": {
"name": "user",
"description": "",
"singularName": "user",
"pluralName": "users",
"displayName": "User"
},
"options": {
"draftAndPublish": false
},
"attributes": {
"username": {
"type": "string",
"minLength": 3,
"unique": true,
"configurable": false,
"required": true
},
"email": {
"type": "email",
"minLength": 6,
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true,
"searchable": false
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmationToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmed": {
"type": "boolean",
"default": false,
"configurable": false
},
"blocked": {
"type": "boolean",
"default": false,
"configurable": false
},
"role": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.role",
"inversedBy": "users",
"configurable": false
}
}
}

View File

@@ -0,0 +1,18 @@
export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register(/*{ strapi }*/) {},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {},
};

View File

@@ -0,0 +1,23 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/server",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"include": [
"./",
"./**/*.ts",
"./**/*.js",
"src/**/*.json"
],
"exclude": [
"node_modules/",
"build/",
"dist/",
".cache/",
".tmp/",
"src/admin/",
"**/*.test.*",
"src/plugins/**"
]
}

View File

@@ -0,0 +1,25 @@
import type { Attribute, Schema } from '@strapi/strapi';
export interface FinishedTasksFinshedTasks extends Schema.Component {
collectionName: 'components_finished_tasks_finshed_tasks';
info: {
description: '';
displayName: 'finshed_tasks';
};
attributes: {
status: Attribute.Enumeration<['pending_prize', 'claimed']>;
task: Attribute.Relation<
'finished-tasks.finshed-tasks',
'oneToOne',
'api::task.task'
>;
};
}
declare module '@strapi/types' {
export module Shared {
export interface Components {
'finished-tasks.finshed-tasks': FinishedTasksFinshedTasks;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
export const toFixed = (value: number, decimals: number = 4) => {
return Number(value.toFixed(decimals));
};