Skip to content

Commit

Permalink
Merge pull request #35 from ElectroAAC/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
WalistonBelles authored May 8, 2022
2 parents 3145e18 + 800e690 commit f48014c
Show file tree
Hide file tree
Showing 107 changed files with 2,668 additions and 2,781 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ This repository follows the semantic commit pattern, with the addition of the ta
<li> [x] Show lastnews </li>
</ul>

<br>

### View character informations
<ul>
<li> [x] Show character info </li>
Expand Down Expand Up @@ -130,8 +128,7 @@ This repository follows the semantic commit pattern, with the addition of the ta
<li> [x] Manage Guilds </li>
<ul>
<li> [x] Invite Player </li>
<li> [ ] Remove Invite </li>
<li> [ ] Remove Invite </li>
<li> [x] Remove Invite </li>
<li> [x] Promove Player </li>
<li> [x] Demote Player </li>
<li> [x] Change MOTD </li>
Expand Down
16 changes: 8 additions & 8 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PORT=3333
HOST=0.0.0.0
NODE_ENV=development
APP_KEY=ZBcXCJO_weKSwqTJFUGyBjux1Q3_pnS7
APP_KEY=YOUR_API_KEY
DRIVE_DISK=local

DB_CONNECTION=mysql
Expand All @@ -14,11 +14,11 @@ MYSQL_DB_NAME=YOUR_DATABASE_GAME

CACHE_VIEWS=false

SMTP_HOST=localhost
SMTP_PORT=587
SMTP_USERNAME=<username>
SMTP_PASSWORD=<password>
SMTP_HOST=localhost # String. Example: localhost
SMTP_PORT=YOUR_SMTP_PORT # Number. Example: 587
SMTP_USERNAME=<username> # String. Example: electro123
SMTP_PASSWORD=<password> # String. Example: electro123

CHARACTERS_PER_ACCOUNT=MAX_CHARACTERS_PER_ACCOUNT
CHANGE_NAME=ALLOW_NAME_CHANGE
POINTS_TO_CHANGE_NAME=PRICE_TO_CHANGE_NAME
CHARACTERS_PER_ACCOUNT=MAX_CHARACTERS_PER_ACCOUNT # Number. Example: CHARACTERS_PER_ACCOUNT=10
CHANGE_NAME=ALLOW_NAME_CHANGE # Boolean. Example: CHANGE_NAME=true
POINTS_TO_CHANGE_NAME=PRICE_TO_CHANGE_NAME # Number. Example: POINTS_TO_CHANGE_NAME=10
36 changes: 30 additions & 6 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ $ npm install
# Create database structure
$ node ace migration:run

# Create account admin and character sample
$ node ace db:seed

# server with changes watcher
$ npm run dev

Expand All @@ -29,10 +32,6 @@ $ npm run start
| METHOD | ENDPOINT | DESCRIPTION |
| :----- | :-------------------------------| :------------------------------------ |
| GET | /news/list/:page/:limit | Get news |
| GET | /news/listDashboard/:page/:limit| Get news to Dashboard |
| POST | /news/create-post | Create new post |
| GET | /news/find/:id | Find post |
| POST | /news/edit | Edit post |

<br>

Expand Down Expand Up @@ -105,7 +104,7 @@ $ npm run start
| :----- | :------------------------- | :------------------------------------ |
| GET | /guilds/:page/:limit | Get all guilds |
| GET | /guild/view/:name | Get guild info |
| GET | /guild/players-with-guild | Get guild info |
| GET | /guild/players-without-guild| Get guild info |
| POST | /guild/create-guild | Create Guild |
| POST | /guild/invite | Invite character |
| POST | /guild/invites | Get all invites |
Expand All @@ -120,6 +119,22 @@ $ npm run start

<br>

## 🕵🏾‍♂️ Routes Shop

| METHOD | ENDPOINT | DESCRIPTION |
| :----- | :-------------------------------| :------------------------------------ |
| GET | /shop/category/list | Get all categories |
| POST | /shop/category/create | Create new category |
| PUT | /shop/category/update | Update category |
| DELETE | /shop/category/destroy/:id | Delete category |
| GET | /shop/item/list | Get all items |
| POST | /shop/item/create | Create new offer item |
| PUT | /shop/item/update | Update offer item |
| DELETE | /shop/item/destroy/:id | Delete offer item |
| POST | //shop/purchase | Purchase Items |

<br>

## 🕵🏾‍♂️ Routes Dashboard

| METHOD | ENDPOINT | DESCRIPTION |
Expand Down Expand Up @@ -148,4 +163,13 @@ $ npm run start
| GET | /dashboard/character/:name | Find character |
| GET | /dashboard/character-skills/:id | Find character |
| POST | /dashboard/character | Update character |
| POST | /dashboard/character-skills | Update characterSkills |
| POST | /dashboard/character-skills | Update characterSkills |

## 🕵🏾‍♂️ Routes Dashboard - News

| METHOD | ENDPOINT | DESCRIPTION |
| :----- | :-------------------------------| :------------------------------------ |
| GET | /news/listDashboard/:page/:limit| Get news to Dashboard |
| POST | /news/create | Create new post |
| GET | /news/find/:id | Find post |
| PATCH | /news/edit | Update post |
20 changes: 4 additions & 16 deletions backend/app/Controllers/Account/Characters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export default class CharactersAccount {
return ctx.response.status(404).send({ message: 'Vocation invalid'});
}

const characterCopy: Player[] = await this.characterView.findByName(vocation.name) as Player[];
const characterCopy: Player[] = await this.characterView.getByName(vocation.name) as Player[];

if (!characterCopy.length) {
console.log("Error find Sample Character: Edit file Vocations in contracts/enums/Vocations and set valid characters to copy names. Name Character to copy: " + vocation.name + " doesn\'t exist.");
return ctx.response.status(404).send({ message: "Wrong characters configuration. Try again or contact with admin."});
}

const newPlayer = Object.assign(characterCopy[0], {
const newPlayer = {...characterCopy[0],
id: null,
name: data.name.charAt(0).toUpperCase() + data.name.slice(1).toLowerCase(),
account_id: account.id,
Expand All @@ -56,23 +56,11 @@ export default class CharactersAccount {
posz: 0,
balance: 0,
created: 0
});
};

const result = await this.characterRepository.create(newPlayer);

const player: Player[] = await this.characterView.findById(result[0]) as Player[];

if (!player.length) {
return ctx.response.status(404).send({ message: "Error. Can't create character. Probably problem with database. Please try again later or contact with admin."});
}

for(let i = 0; i < 7; i++) {
const skillExists = await this.characterView.checkSkillId(player[0].id, i);

if (!skillExists.length) {
await this.character.insertSkill(player[0].id, i);
}
}
const player: Player[] = await this.characterView.getById(result[0]) as Player[];

const items_to_copy: Item[] = await this.characterView.getItems(characterCopy[0].id) as Item[];

Expand Down
3 changes: 0 additions & 3 deletions backend/app/Controllers/Account/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class AccountController {
public async show(ctx: HttpContextContract) {
const account = ctx.auth.user!;
/**
* @TODO => Filtrar somente os dados que devem ser retornados a fins de consumo no frontend
*/
return account;
}
}
14 changes: 2 additions & 12 deletions backend/app/Controllers/Account/Register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,24 @@ export default class AccountRegisterController {
email,
name,
password,
salt: "",
type: 1,
premdays: 0,
lastday: 0,
key: "",
blocked: 0,
warnings : 0,
group_id : 1,
vip_time : 1,
web_lastlogin : 1298670924,
web_lastlogin : 0,
web_flags : 0,
email_hash : "",
email_verified : 0,
email_new : "",
email_new_time : 0,
created : 0,
rlname : "",
location : "",
country : "",
page_access : 0,
email_code : "0",
email_next : 0,
premium_points : 0,
vote : 0,
last_post : 0,
flag : "",
nickname : "",
avatar : "",
about_me : ""
});

await account.save();
Expand Down
6 changes: 3 additions & 3 deletions backend/app/Controllers/Dashboard/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class AccountsController {

public async index(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const accounts = await this.accountView.getTotalAccounts();

Expand All @@ -29,7 +29,7 @@ export default class AccountsController {

public async show(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const account = await this.accountView.getAccountByName(ctx.request.param('name')) as AccountModel[];

Expand All @@ -48,7 +48,7 @@ export default class AccountsController {

public async update(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');
const data = await ctx.request.validate(UpdateValidator);

const account = await this.account.validateName(data.id, data.name);
Expand Down
2 changes: 1 addition & 1 deletion backend/app/Controllers/Dashboard/Guilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class GuildsController {

public async show(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const accounts = await this.guildView.getTotalGuilds();

Expand Down
50 changes: 34 additions & 16 deletions backend/app/Controllers/Dashboard/News.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class AccountsController {

public async store(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const data = await ctx.request.validate(StoreValidator);

Expand All @@ -38,7 +38,11 @@ export default class AccountsController {
created_at: new Date()
}

await this.newsRepository.create(news);
const result = await this.newsRepository.create(news);

if (!result.length) {
return ctx.response.status(404).send({ message: "Error creating a post."});
}

return ctx.response.status(200).send({ status: 200, message: 'New Post created successfully!'});
} catch (err) {
Expand All @@ -48,28 +52,42 @@ export default class AccountsController {
}

public async show(ctx: HttpContextContract) {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
try {
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const page = await this.newsView.findNewsById(ctx.request.param('id'));
if (!page.length) {
return ctx.response.status(404).send({ message: 'News not found.' });
const page = await this.newsView.findNewsById(ctx.request.param('id'));
if (!page.length) {
return ctx.response.status(404).send({ message: 'News not found.' });
}
return ctx.response.status(200).send({ status: 200, page });
} catch (err) {
console.log('Error getNews Query: ', err);
return ctx.response.status(400).send({ error: 'An error occurred, check the api console.'});
}
return ctx.response.status(200).send({ status: 200, page });
}

public async update(ctx: HttpContextContract) {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
try {
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const data = await ctx.request.validate(UpdateValidator);
const data = await ctx.request.validate(UpdateValidator);

const account = ctx.auth.user;
const account = ctx.auth.user;

if (!account || !account.id) {
return ctx.response.unauthorized();
}
if (!account || !account.id) {
return ctx.response.unauthorized();
}

await this.newsRepository.update(data.news_id, data);

return ctx.response.status(200).send({ status: 200, message: "Post successfully updated." });
const result: any = await this.newsRepository.update(data.news_id, data);

if (result === 0) {
return ctx.response.status(404).send({ message: "Error updating post"});
}

return ctx.response.status(200).send({ status: 200, message: "Post successfully updated." });
} catch (err) {
console.log('Error updateNews Query: ', err);
return ctx.response.status(400).send({ error: 'An error occurred, check the api console.'});
}
}
}
4 changes: 2 additions & 2 deletions backend/app/Controllers/Dashboard/PlayerSkills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class PlayersController {

public async show(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const skills = await this.skillView.getCharacterSkills(ctx.request.param('id'));

Expand All @@ -25,7 +25,7 @@ export default class PlayersController {

public async update(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const data = await ctx.request.validate(UpdateValidator);

Expand Down
8 changes: 4 additions & 4 deletions backend/app/Controllers/Dashboard/Players.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class PlayersController {

public async index(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const accounts = await this.characterView.getTotalCharacters();

Expand All @@ -22,9 +22,9 @@ export default class PlayersController {

public async show(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const character = await this.characterView.findByName(ctx.request.param('name'));
const character = await this.characterView.getByName(ctx.request.param('name'));

if (!character.length) {
return ctx.response.status(404).send({ message: "Character not found!" });
Expand All @@ -40,7 +40,7 @@ export default class PlayersController {

public async update(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const data = await ctx.request.validate(UpdateValidator);

Expand Down
2 changes: 1 addition & 1 deletion backend/app/Controllers/Dashboard/PremiumPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class PremiumPointsController {

public async show(ctx: HttpContextContract) {
try {
await ctx.bouncer.with('DashboardPolicy').authorize('viewList');
await ctx.bouncer.with('DashboardPolicy').authorize('admin');

const accounts = await this.accountView.getTopPremiumPoints();

Expand Down
Loading

0 comments on commit f48014c

Please sign in to comment.