Skip to content

Commit

Permalink
feat: Linted and formatted the code
Browse files Browse the repository at this point in the history
  • Loading branch information
dm94 committed Dec 3, 2024
1 parent 3640641 commit ba56a4d
Show file tree
Hide file tree
Showing 62 changed files with 297 additions and 277 deletions.
7 changes: 0 additions & 7 deletions .prettierrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"recommended": true,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "stiletto-node-api",
"version": "3.0.4",
"version": "3.0.5",
"description": "API for [Stiletto Web](https://github.com/dm94/stiletto-web)",
"type": "module",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint": "biome lint --write ./src",
"format": "biome format --write ./src",
"check:types": "tsc --noEmit",
"build": "esbuild `find src \\( -name '*.ts' \\)` --platform=node --outdir=build --resolve-extensions=.js",
"build:docker:prod": "docker build . -t my-fastify-app --build-arg APP_ENV=production",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const configPlugin: FastifyPluginAsync = async (server) => {
const validate = ajv.compile(ConfigSchema);
const valid = validate(process.env);
if (!valid) {
throw new Error('.env file validation failed - ' + JSON.stringify(validate.errors, null, 2));
throw new Error(`.env file validation failed - ${JSON.stringify(validate.errors, null, 2)}`);
}
server.decorate('config', process.env);
};
Expand Down
23 changes: 12 additions & 11 deletions src/routes/bot/clans/_discordid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import {
Error404Default,
Error503Default,
} from '@customtypes/errors';
import { Permission, Permissions, PermissionsSchema } from '@customtypes/permissions';
import { RelationshipInfo, RelationshipSchema } from '@customtypes/relationships';
import {
import { Permission, type Permissions, PermissionsSchema } from '@customtypes/permissions';
import { type RelationshipInfo, RelationshipSchema } from '@customtypes/relationships';
import type {
GetDiscordServerRequest,
KickFromClanRequest,
LinkClanRequest,
} from '@customtypes/requests/bot';
import { hasPermissions } from '@services/permission';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.post<LinkClanRequest>(
Expand Down Expand Up @@ -71,7 +71,7 @@ const routes: FastifyPluginAsync = async (server) => {
'select users.discordID, users.clanid clanid, clans.leaderid from users, clans where users.clanid=clans.clanid and users.discordID=?',
[memberId],
(e, r) => {
if (r && r[0]) {
if (r?.[0]) {
const clanId = r[0].clanid;
const leaderId = r[0].leaderid;

Expand Down Expand Up @@ -156,7 +156,7 @@ const routes: FastifyPluginAsync = async (server) => {
'select users.discordID, users.clanid from users, clans where users.clanid=clans.clanid and users.nickname=? and clans.discordid=?',
[nick, serverDiscordId],
(e, r) => {
if (r && r[0]) {
if (r?.[0]) {
const clanId = r[0].clanid;
const discordId = r[0].discordID;

Expand All @@ -167,14 +167,15 @@ const routes: FastifyPluginAsync = async (server) => {
]);
server.mysql.query('update users set clanid=null where discordID=?', [discordId]);
return reply.code(204).send();
} else {
return reply.code(401).send();
}
} else if (e) {
return reply.code(401).send();
}

if (e) {
return reply.code(503).send();
} else {
return reply.code(404).send();
}

return reply.code(404).send();
},
);
},
Expand Down
23 changes: 15 additions & 8 deletions src/routes/bot/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { DiscordConfigBot, DiscordConfigBotSchema, Languages } from '@customtypes/discordconfig';
import {
type DiscordConfigBot,
DiscordConfigBotSchema,
Languages,
} from '@customtypes/discordconfig';
import {
Error400Default,
Error401Default,
Error404Default,
Error503Default,
} from '@customtypes/errors';
import { GetDiscordServerRequest, UpdateBotConfigByServerRequest } from '@customtypes/requests/bot';
import type {
GetDiscordServerRequest,
UpdateBotConfigByServerRequest,
} from '@customtypes/requests/bot';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.get<{ Reply: DiscordConfigBot[] }>(
Expand All @@ -31,7 +38,7 @@ const routes: FastifyPluginAsync = async (server) => {
},
},
},
(request, reply) => {
(_request, reply) => {
server.mysql.query(
'select serverdiscordid, botlanguaje, readclanlog, automatickick, setnotreadypvp, walkeralarm from botconfigs',
(err, result: DiscordConfigBot[]) => {
Expand Down Expand Up @@ -85,13 +92,13 @@ const routes: FastifyPluginAsync = async (server) => {
'select serverdiscordid, botlanguaje, readclanlog, automatickick, setnotreadypvp, walkeralarm from botconfigs where serverdiscordid=?',
[serverDiscordId],
(err, result) => {
if (result && result[0]) {
if (result?.[0]) {
return reply.code(200).send(result[0]);
} else if (err) {
}
if (err) {
return reply.code(503).send();
} else {
return reply.code(404).send();
}
return reply.code(404).send();
},
);
},
Expand Down
13 changes: 6 additions & 7 deletions src/routes/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {
Error404Default,
Error503Default,
} from '@customtypes/errors';
import { CreateTradefromBotRequest, GetWhoHasLearnRequest } from '@customtypes/requests/bot';
import type { CreateTradefromBotRequest, GetWhoHasLearnRequest } from '@customtypes/requests/bot';
import {
TechTreeInfo,
type TechTreeInfo,
TechTreeSchema,
TechUserInfo,
type TechUserInfo,
TechUserSchema,
Tree,
} from '@customtypes/techtree';
import { TradeType } from '@customtypes/trades';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.get<GetWhoHasLearnRequest, { Reply: TechUserInfo[] }>(
Expand Down Expand Up @@ -161,7 +161,7 @@ const routes: FastifyPluginAsync = async (server) => {
'select discordTag from users where discordID=?',
[request.params.discordid],
(e, rows) => {
if (rows && rows[0] && rows[0].discordTag) {
if (rows?.[0]?.discordTag) {
const discordtag = rows[0].discordTag;

const techCollection = server.mongo.client.db('lastoasis').collection('tech');
Expand All @@ -175,9 +175,8 @@ const routes: FastifyPluginAsync = async (server) => {
techCollection.findOne({ discordtag: discordtag }).then((techTree) => {
if (techTree) {
return reply.code(200).send(techTree);
} else {
return reply.code(201).send();
}
return reply.code(201).send();
});
});
} else if (e) {
Expand Down
11 changes: 6 additions & 5 deletions src/routes/bot/walkers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Error400Default, Error401Default, Error503Default } from '@customtypes/errors';
import {
import type {
AddWalkerRequest,
BotEditWalkerRequest,
GetWalkersByServerRequest,
} from '@customtypes/requests/bot';
import { WalkerInfo, WalkerSchema, WalkerUse, WalkerType } from '@customtypes/walkers';
import { type WalkerInfo, WalkerSchema, WalkerUse, WalkerType } from '@customtypes/walkers';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.get<GetWalkersByServerRequest, { Reply: WalkerInfo[] }>(
Expand Down Expand Up @@ -155,7 +155,8 @@ const routes: FastifyPluginAsync = async (server) => {
console.log('result', result);
if (result) {
return reply.code(200).send(result as WalkerInfo[]);
} else if (err) {
}
if (err) {
console.log('err', err);
return reply.code(503).send();
}
Expand Down Expand Up @@ -225,7 +226,7 @@ const routes: FastifyPluginAsync = async (server) => {
'select * from walkers where name=? and discorid=?',
[name, discordid],
(err, result) => {
if (result && result[0]) {
if (result?.[0]) {
server.mysql.query(
'update walkers set datelastuse=?, lastUser=?, walkerID=? where name=? and discorid=?',
[date, lastuser, walkerid, name, discordid],
Expand Down
22 changes: 13 additions & 9 deletions src/routes/clans/_clanid/discordbot/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { DiscordConfig, DiscordConfigSchema, Languages } from '@customtypes/discordconfig';
import { GetDiscordConfigRequest, UpdateDiscordConfigRequest } from '@customtypes/requests/clans';
import { type DiscordConfig, DiscordConfigSchema, Languages } from '@customtypes/discordconfig';
import type {
GetDiscordConfigRequest,
UpdateDiscordConfigRequest,
} from '@customtypes/requests/clans';
import { Permission } from '@customtypes/permissions';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';
import { addPermissions } from '@services/permission';
import {
Error400Default,
Expand Down Expand Up @@ -55,7 +58,7 @@ const routes: FastifyPluginAsync = async (server) => {
'select serverdiscordid, botlanguaje, readclanlog, automatickick, setnotreadypvp, walkeralarm from botconfigs where serverdiscordid=?',
request.dbuser.serverdiscord,
(err, result) => {
if (result && result[0]) {
if (result?.[0]) {
return reply.code(200).send({
discordid: result[0].serverdiscordid,
botLanguaje: result[0].botlanguaje,
Expand All @@ -64,11 +67,11 @@ const routes: FastifyPluginAsync = async (server) => {
setNotReadyPVP: result[0].setnotreadypvp,
walkerAlarm: result[0].walkeralarm,
});
} else if (err) {
}
if (err) {
return reply.code(503).send();
} else {
return reply.code(404).send();
}
return reply.code(404).send();
},
);
} else {
Expand All @@ -85,7 +88,7 @@ const routes: FastifyPluginAsync = async (server) => {
{
onRequest: [
server.authenticate,
(request, reply, done) => addPermissions(server, request, done),
(request, _reply, done) => addPermissions(server, request, done),
],
schema: {
description: ' Update the bot Config',
Expand Down Expand Up @@ -184,7 +187,8 @@ const routes: FastifyPluginAsync = async (server) => {
return reply.code(200).send({
message: 'Config updated',
});
} else if (err) {
}
if (err) {
return reply.code(503).send();
}
},
Expand Down
24 changes: 14 additions & 10 deletions src/routes/clans/_clanid/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { ClanInfo, ClanSchema } from '@customtypes/clans';
import { type ClanInfo, ClanSchema } from '@customtypes/clans';
import {
Error400Default,
Error401Default,
Error404Default,
Error405Default,
Error503Default,
} from '@customtypes/errors';
import { DeleteClanRequest, GetClanRequest, UpdateClanRequest } from '@customtypes/requests/clans';
import type {
DeleteClanRequest,
GetClanRequest,
UpdateClanRequest,
} from '@customtypes/requests/clans';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.get<GetClanRequest, { Reply: ClanInfo }>(
Expand Down Expand Up @@ -40,13 +44,13 @@ const routes: FastifyPluginAsync = async (server) => {
'select clans.clanid, clans.name, clans.discordid, clans.leaderid, clans.invitelink, clans.recruitment, clans.flagcolor, clans.symbol, clans.region, users.discordTag from clans, users where clans.leaderid=users.discordID and clans.clanid=?',
clanId,
(err, result) => {
if (result && result[0]) {
if (result?.[0]) {
return reply.code(200).send(result[0]);
} else if (err) {
}
if (err) {
return reply.code(503).send();
} else {
return reply.code(404).send();
}
return reply.code(404).send();
},
);
} else {
Expand Down Expand Up @@ -162,7 +166,8 @@ const routes: FastifyPluginAsync = async (server) => {
return reply.code(200).send({
message: 'Clan updated',
});
} else if (err) {
}
if (err) {
return reply.code(503).send();
}
},
Expand Down Expand Up @@ -249,9 +254,8 @@ const routes: FastifyPluginAsync = async (server) => {
});

return reply.code(204).send();
} else {
return reply.code(400).send();
}
return reply.code(400).send();
},
);
};
Expand Down
9 changes: 5 additions & 4 deletions src/routes/clans/_clanid/members/_memberid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {
} from '@customtypes/errors';
import { MemberActions } from '@customtypes/members';
import { Permission } from '@customtypes/permissions';
import { GetMemberRequest } from '@customtypes/requests/members';
import type { GetMemberRequest } from '@customtypes/requests/members';
import { addPermissions } from '@services/permission';
import { Type } from '@sinclair/typebox';
import { FastifyPluginAsync } from 'fastify';
import type { FastifyPluginAsync } from 'fastify';

const routes: FastifyPluginAsync = async (server) => {
server.put<GetMemberRequest>(
'/',
{
onRequest: [
server.authenticate,
(request, reply, done) => addPermissions(server, request, done),
(request, _reply, done) => addPermissions(server, request, done),
],
schema: {
description:
Expand Down Expand Up @@ -107,7 +107,8 @@ const routes: FastifyPluginAsync = async (server) => {
return reply.code(202).send({
message: 'The change has been made correctly',
});
} else if (err) {
}
if (err) {
return reply.code(503).send();
}
},
Expand Down
Loading

0 comments on commit ba56a4d

Please sign in to comment.