feat(): Add veritication mark #50

Merged
alekswilc merged 2 commits from v3 into preview 2024-11-09 19:58:37 +01:00
5 changed files with 41 additions and 13 deletions
Showing only changes of commit d86f477434 - Show all commits

View File

@ -4,6 +4,7 @@ import { MBlacklist } from "../../mongo/blacklist.js";
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
import { removeProperties } from "../../util/functions.js";
import { ILog, MLog } from "../../mongo/logs.js";
import { MProfile } from "../../mongo/profile.js";
export class LogRoute
@ -24,6 +25,7 @@ export class LogRoute
}
const log = await MLog.findOne({ id }) || await MTrainLog.findOne({ id });
if (!log)
{
res.status(404).json(new ErrorResponseBuilder()
@ -31,8 +33,13 @@ export class LogRoute
.setData("Invalid Id parameter").toJSON());
return;
}
const profile = await MProfile.findOne({ steam: log.userSteamId });
res.status(200).json(new SuccessResponseBuilder().setCode(200).setData(removeProperties<Omit<(ILog | ITrainLog), "_id" | "__v">>(log.toJSON(), [ "_id", "__v" ])));
res.status(200).json(new SuccessResponseBuilder().setCode(200).setData({
verified: profile?.verified,
...removeProperties<Omit<(ILog | ITrainLog), "_id" | "__v">>(log.toJSON(), [ "_id", "__v" ])
}));
});
return app;

View File

@ -4,6 +4,7 @@ import { MProfile } from "../../mongo/profile.js";
import { MBlacklist } from "../../mongo/blacklist.js";
import { SteamUtil } from "../../util/SteamUtil.js";
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
import { removeProperties } from "../../util/functions.js";
export class ProfilesRoute
{
@ -11,7 +12,6 @@ export class ProfilesRoute
{
const app = Router();
app.get("/:id", async (req, res) =>
{
if (!req.params.id)
@ -19,13 +19,15 @@ export class ProfilesRoute
res.redirect("/");
return;
}
const player = await MProfile.findOne({ steam: req.params.id });
if (!player)
{
res.status(404).json(new ErrorResponseBuilder()
.setCode(404).setData("Profile not found! (propably private)"));
.setCode(404).setData("Profile not found! (probably private)"));
return;
}
const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
if (blacklist && blacklist.status)
{
@ -33,23 +35,18 @@ export class ProfilesRoute
.setCode(403).setData("Profile blacklisted!"));
return;
}
const steam = await SteamUtil.getPlayer(player?.steam!);
const steamStats = await SteamUtil.getPlayerStats(player?.steam!);
res.json(
new SuccessResponseBuilder()
.setCode(200)
.setData({
player, steam, steamStats,
player: removeProperties(player, ['_id', '__v']), steam, steamStats,
})
.toJSON(),
);
res.render("profiles/index.ejs", {
player, steam, steamStats: steamStats,
msToTime,
});
});
return app;

View File

@ -8,6 +8,7 @@ import { SteamUtil } from "../../util/SteamUtil.js";
import { GitUtil } from "../../util/git.js";
import { removeProperties } from "../../util/functions.js";
import { SuccessResponseBuilder } from "../responseBuilder.js";
import { MProfile } from "../../mongo/profile.js";
const generateSearch = (regex: RegExp) => [
{
@ -36,7 +37,7 @@ export class StationsRoute
app.get("/", async (req, res) =>
{
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
const profiles = await MProfile.find({ verified: true });
const filter: PipelineStage[] = [];
@ -48,13 +49,20 @@ export class StationsRoute
},
});
const records = await MLog.aggregate(filter)
.sort({ leftDate: -1 })
.limit(30);
res.json(
new SuccessResponseBuilder<{ records: Omit<ILog, "_id" | "__v">[] }>()
.setCode(200)
.setData({ records: records.map(x => removeProperties<Omit<ILog, "_id" | "__v">>(x, [ "_id", "__v" ])) })
.setData({ records: records.map(x => {
return {
...removeProperties<Omit<ILog, "_id" | "__v">>(x, [ "_id", "__v" ]),
verified: profiles.find(xx => xx.steam === x.userSteamId)
}
}) })
.toJSON(),
);
});

View File

@ -8,6 +8,7 @@ import { SteamUtil } from "../../util/SteamUtil.js";
import { GitUtil } from "../../util/git.js";
import { SuccessResponseBuilder } from "../responseBuilder.js";
import { removeProperties } from "../../util/functions.js";
import { MProfile } from "../../mongo/profile.js";
const generateSearch = (regex: RegExp) => [
{
@ -33,6 +34,7 @@ export class TrainsRoute
app.get("/", async (req, res) =>
{
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
const profiles = await MProfile.find({ verified: true });
const filter: PipelineStage[] = [];
@ -53,7 +55,15 @@ export class TrainsRoute
res.json(
new SuccessResponseBuilder<{ records: Omit<ITrainLog, "_id" | "__v">[] }>()
.setCode(200)
.setData({ records: records.map(x => removeProperties<Omit<ITrainLog, "_id" | "__v">>(x, [ "_id", "__v" ])) })
.setData({
records: records.map(x =>
{
return {
...removeProperties<Omit<ITrainLog, "_id" | "__v">>(x, [ "_id", "__v" ]),
verified: profiles.find(xx => xx.steam === x.userSteamId)
};
}),
})
.toJSON(),
);
});

View File

@ -45,6 +45,11 @@ export const raw_schema = {
required: false,
default: 0,
},
verified: {
type: Boolean,
required: true,
default: false
}
};
const schema = new Schema<IProfile>(raw_schema);
@ -76,4 +81,5 @@ export interface IProfile
trainPoints: number;
steamName: string;
trainDistance: number;
verified: boolean;
}