feat(): Add veritication mark #50
@ -4,6 +4,7 @@ import { MBlacklist } from "../../mongo/blacklist.js";
|
|||||||
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
|
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
|
||||||
import { removeProperties } from "../../util/functions.js";
|
import { removeProperties } from "../../util/functions.js";
|
||||||
import { ILog, MLog } from "../../mongo/logs.js";
|
import { ILog, MLog } from "../../mongo/logs.js";
|
||||||
|
import { MProfile } from "../../mongo/profile.js";
|
||||||
|
|
||||||
|
|
||||||
export class LogRoute
|
export class LogRoute
|
||||||
@ -24,6 +25,7 @@ export class LogRoute
|
|||||||
}
|
}
|
||||||
|
|
||||||
const log = await MLog.findOne({ id }) || await MTrainLog.findOne({ id });
|
const log = await MLog.findOne({ id }) || await MTrainLog.findOne({ id });
|
||||||
|
|
||||||
if (!log)
|
if (!log)
|
||||||
{
|
{
|
||||||
res.status(404).json(new ErrorResponseBuilder()
|
res.status(404).json(new ErrorResponseBuilder()
|
||||||
@ -31,8 +33,13 @@ export class LogRoute
|
|||||||
.setData("Invalid Id parameter").toJSON());
|
.setData("Invalid Id parameter").toJSON());
|
||||||
return;
|
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;
|
return app;
|
||||||
|
@ -4,6 +4,7 @@ import { MProfile } from "../../mongo/profile.js";
|
|||||||
import { MBlacklist } from "../../mongo/blacklist.js";
|
import { MBlacklist } from "../../mongo/blacklist.js";
|
||||||
import { SteamUtil } from "../../util/SteamUtil.js";
|
import { SteamUtil } from "../../util/SteamUtil.js";
|
||||||
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
|
import { ErrorResponseBuilder, SuccessResponseBuilder } from "../responseBuilder.js";
|
||||||
|
import { removeProperties } from "../../util/functions.js";
|
||||||
|
|
||||||
export class ProfilesRoute
|
export class ProfilesRoute
|
||||||
{
|
{
|
||||||
@ -11,7 +12,6 @@ export class ProfilesRoute
|
|||||||
{
|
{
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
|
|
||||||
app.get("/:id", async (req, res) =>
|
app.get("/:id", async (req, res) =>
|
||||||
{
|
{
|
||||||
if (!req.params.id)
|
if (!req.params.id)
|
||||||
@ -19,13 +19,15 @@ export class ProfilesRoute
|
|||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const player = await MProfile.findOne({ steam: req.params.id });
|
const player = await MProfile.findOne({ steam: req.params.id });
|
||||||
if (!player)
|
if (!player)
|
||||||
{
|
{
|
||||||
res.status(404).json(new ErrorResponseBuilder()
|
res.status(404).json(new ErrorResponseBuilder()
|
||||||
.setCode(404).setData("Profile not found! (propably private)"));
|
.setCode(404).setData("Profile not found! (probably private)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
|
const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
|
||||||
if (blacklist && blacklist.status)
|
if (blacklist && blacklist.status)
|
||||||
{
|
{
|
||||||
@ -33,23 +35,18 @@ export class ProfilesRoute
|
|||||||
.setCode(403).setData("Profile blacklisted!"));
|
.setCode(403).setData("Profile blacklisted!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const steam = await SteamUtil.getPlayer(player?.steam!);
|
const steam = await SteamUtil.getPlayer(player?.steam!);
|
||||||
const steamStats = await SteamUtil.getPlayerStats(player?.steam!);
|
const steamStats = await SteamUtil.getPlayerStats(player?.steam!);
|
||||||
|
|
||||||
|
|
||||||
res.json(
|
res.json(
|
||||||
new SuccessResponseBuilder()
|
new SuccessResponseBuilder()
|
||||||
.setCode(200)
|
.setCode(200)
|
||||||
.setData({
|
.setData({
|
||||||
player, steam, steamStats,
|
player: removeProperties(player, ['_id', '__v']), steam, steamStats,
|
||||||
})
|
})
|
||||||
.toJSON(),
|
.toJSON(),
|
||||||
);
|
);
|
||||||
|
|
||||||
res.render("profiles/index.ejs", {
|
|
||||||
player, steam, steamStats: steamStats,
|
|
||||||
msToTime,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
@ -8,6 +8,7 @@ import { SteamUtil } from "../../util/SteamUtil.js";
|
|||||||
import { GitUtil } from "../../util/git.js";
|
import { GitUtil } from "../../util/git.js";
|
||||||
import { removeProperties } from "../../util/functions.js";
|
import { removeProperties } from "../../util/functions.js";
|
||||||
import { SuccessResponseBuilder } from "../responseBuilder.js";
|
import { SuccessResponseBuilder } from "../responseBuilder.js";
|
||||||
|
import { MProfile } from "../../mongo/profile.js";
|
||||||
|
|
||||||
const generateSearch = (regex: RegExp) => [
|
const generateSearch = (regex: RegExp) => [
|
||||||
{
|
{
|
||||||
@ -36,7 +37,7 @@ export class StationsRoute
|
|||||||
app.get("/", async (req, res) =>
|
app.get("/", async (req, res) =>
|
||||||
{
|
{
|
||||||
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
|
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
|
||||||
|
const profiles = await MProfile.find({ verified: true });
|
||||||
const filter: PipelineStage[] = [];
|
const filter: PipelineStage[] = [];
|
||||||
|
|
||||||
|
|
||||||
@ -48,13 +49,20 @@ export class StationsRoute
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const records = await MLog.aggregate(filter)
|
const records = await MLog.aggregate(filter)
|
||||||
.sort({ leftDate: -1 })
|
.sort({ leftDate: -1 })
|
||||||
.limit(30);
|
.limit(30);
|
||||||
|
|
||||||
res.json(
|
res.json(
|
||||||
new SuccessResponseBuilder<{ records: Omit<ILog, "_id" | "__v">[] }>()
|
new SuccessResponseBuilder<{ records: Omit<ILog, "_id" | "__v">[] }>()
|
||||||
.setCode(200)
|
.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(),
|
.toJSON(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ import { SteamUtil } from "../../util/SteamUtil.js";
|
|||||||
import { GitUtil } from "../../util/git.js";
|
import { GitUtil } from "../../util/git.js";
|
||||||
import { SuccessResponseBuilder } from "../responseBuilder.js";
|
import { SuccessResponseBuilder } from "../responseBuilder.js";
|
||||||
import { removeProperties } from "../../util/functions.js";
|
import { removeProperties } from "../../util/functions.js";
|
||||||
|
import { MProfile } from "../../mongo/profile.js";
|
||||||
|
|
||||||
const generateSearch = (regex: RegExp) => [
|
const generateSearch = (regex: RegExp) => [
|
||||||
{
|
{
|
||||||
@ -33,6 +34,7 @@ export class TrainsRoute
|
|||||||
app.get("/", async (req, res) =>
|
app.get("/", async (req, res) =>
|
||||||
{
|
{
|
||||||
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
|
const s = req.query.q?.toString().split(",").map(x => new RegExp(x, "i"));
|
||||||
|
const profiles = await MProfile.find({ verified: true });
|
||||||
|
|
||||||
const filter: PipelineStage[] = [];
|
const filter: PipelineStage[] = [];
|
||||||
|
|
||||||
@ -53,7 +55,15 @@ export class TrainsRoute
|
|||||||
res.json(
|
res.json(
|
||||||
new SuccessResponseBuilder<{ records: Omit<ITrainLog, "_id" | "__v">[] }>()
|
new SuccessResponseBuilder<{ records: Omit<ITrainLog, "_id" | "__v">[] }>()
|
||||||
.setCode(200)
|
.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(),
|
.toJSON(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -45,6 +45,11 @@ export const raw_schema = {
|
|||||||
required: false,
|
required: false,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
verified: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const schema = new Schema<IProfile>(raw_schema);
|
const schema = new Schema<IProfile>(raw_schema);
|
||||||
@ -76,4 +81,5 @@ export interface IProfile
|
|||||||
trainPoints: number;
|
trainPoints: number;
|
||||||
steamName: string;
|
steamName: string;
|
||||||
trainDistance: number;
|
trainDistance: number;
|
||||||
|
verified: boolean;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user