🎨 formatting files

This commit is contained in:
Flam3rboy 2021-04-25 19:46:57 +02:00
parent 6722c1556c
commit 5dd97905ab
6 changed files with 35 additions and 70 deletions

15
package-lock.json generated
View File

@ -10,7 +10,7 @@
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@fosscord/server-util": "^1.0.4", "@fosscord/server-util": "^1.0.7",
"@types/jest": "^26.0.22", "@types/jest": "^26.0.22",
"bcrypt": "^5.0.0", "bcrypt": "^5.0.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
@ -581,10 +581,9 @@
} }
}, },
"node_modules/@fosscord/server-util": { "node_modules/@fosscord/server-util": {
"version": "1.0.4", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.0.4.tgz", "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.0.7.tgz",
"integrity": "sha512-TZPUNyOF/dxmVLDscUPQXmikKS/K209Itv15TGVYGHovCFVIfHVbfXxa+u7EVseQJvX7BL1Kyd45IWDE0Qy1jA==", "integrity": "sha512-3vBPCt+lwMS7wk+iRvv+V8qBSnEdNifpPxX97Lfjje/TSWI17Kg29y3BmcGJRC5TwIHTLFtgpNLmZmruhv7ziQ==",
"license": "ISC",
"dependencies": { "dependencies": {
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/mongoose-autopopulate": "^0.10.1", "@types/mongoose-autopopulate": "^0.10.1",
@ -12564,9 +12563,9 @@
} }
}, },
"@fosscord/server-util": { "@fosscord/server-util": {
"version": "1.0.4", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.0.4.tgz", "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.0.7.tgz",
"integrity": "sha512-TZPUNyOF/dxmVLDscUPQXmikKS/K209Itv15TGVYGHovCFVIfHVbfXxa+u7EVseQJvX7BL1Kyd45IWDE0Qy1jA==", "integrity": "sha512-3vBPCt+lwMS7wk+iRvv+V8qBSnEdNifpPxX97Lfjje/TSWI17Kg29y3BmcGJRC5TwIHTLFtgpNLmZmruhv7ziQ==",
"requires": { "requires": {
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/mongoose-autopopulate": "^0.10.1", "@types/mongoose-autopopulate": "^0.10.1",

View File

@ -30,7 +30,7 @@
}, },
"homepage": "https://github.com/fosscord/fosscord-api#readme", "homepage": "https://github.com/fosscord/fosscord-api#readme",
"dependencies": { "dependencies": {
"@fosscord/server-util": "^1.0.4", "@fosscord/server-util": "^1.0.7",
"@types/jest": "^26.0.22", "@types/jest": "^26.0.22",
"bcrypt": "^5.0.0", "bcrypt": "^5.0.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",

View File

@ -25,25 +25,16 @@ router.post(
const query: any[] = [{ phone: login }]; const query: any[] = [{ phone: login }];
if (email) query.push({ email }); if (email) query.push({ email });
const user = await UserModel.findOne( const user = await UserModel.findOne({ $or: query }, `user_data.hash id user_settings.locale user_settings.theme`).exec();
{
$or: query,
},
`user_data.hash id user_settings.locale user_settings.theme`
).exec();
if (!user) { if (!user) {
throw FieldErrors({ throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" } });
login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" },
});
} }
// the salt is saved in the password refer to bcrypt docs // the salt is saved in the password refer to bcrypt docs
const same_password = await bcrypt.compare(password, user.user_data.hash); const same_password = await bcrypt.compare(password, user.user_data.hash);
if (!same_password) { if (!same_password) {
throw FieldErrors({ throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" },
});
} }
const token = await generateToken(user.id); const token = await generateToken(user.id);

View File

@ -27,6 +27,7 @@ router.post("/", check({ messages: [String] }), async (req, res) => {
if (messages.length > maxBulkDelete) throw new HTTPError(`You cannot delete more than ${maxBulkDelete} messages`); if (messages.length > maxBulkDelete) throw new HTTPError(`You cannot delete more than ${maxBulkDelete} messages`);
await MessageModel.deleteMany({ id: { $in: messages } }).exec(); await MessageModel.deleteMany({ id: { $in: messages } }).exec();
await emitEvent({ await emitEvent({
event: "MESSAGE_DELETE_BULK", event: "MESSAGE_DELETE_BULK",
channel_id, channel_id,

View File

@ -1,8 +1,4 @@
import { import { Router, Request, Response } from "express";
Router,
Request,
Response
} from "express";
import { import {
ChannelModel, ChannelModel,
ChannelCreateEvent, ChannelCreateEvent,
@ -10,39 +6,23 @@ import {
UserModel, UserModel,
toObject, toObject,
ChannelType, ChannelType,
Snowflake Snowflake,
trimSpecial,
} from "@fosscord/server-util"; } from "@fosscord/server-util";
import { import { HTTPError } from "lambert-server";
HTTPError import { emitEvent } from "../../../util/Event";
} from "lambert-server"; import { getPublicUser } from "../../../util/User";
import { import { DmChannelCreateSchema } from "../../../schema/Channel";
emitEvent import { check } from "../../../util/instanceOf";
} from "../../../util/Event";
import {
getPublicUser
} from "../../../util/User";
import {
DmChannelCreateSchema
} from "../../../schema/Channel";
import {
check
} from "../../../util/instanceOf";
const router: Router = Router(); const router: Router = Router();
router.get("/", async (req: Request, res: Response) => { router.get("/", async (req: Request, res: Response) => {
const user = await UserModel.findOne({
id: req.user_id
}, {
guilds: true
}).exec();
if (!user) throw new HTTPError("User not found", 404);
var testID = "829044530203328513"; //FOR TEST
var channels = await ChannelModel.find({ var channels = await ChannelModel.find({
recipients: req.user_id, $or: [
type: 1 { recipients: req.user_id, type: ChannelType.DM },
{ recipients: req.user_id, type: ChannelType.GROUP_DM },
],
}).exec(); }).exec();
res.json(toObject(channels)); res.json(toObject(channels));
@ -50,19 +30,21 @@ router.get("/", async (req: Request, res: Response) => {
router.post("/", check(DmChannelCreateSchema), async (req, res) => { router.post("/", check(DmChannelCreateSchema), async (req, res) => {
const body = req.body as DmChannelCreateSchema; const body = req.body as DmChannelCreateSchema;
if (body.recipients.length === 0) throw new HTTPError("You need to specify at least one recipient");
const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM;
const name = trimSpecial(body.name);
const channel = { const channel = {
...body, name,
type,
owner_id: req.user_id, owner_id: req.user_id,
id: Snowflake.generate(), id: Snowflake.generate(),
type: ChannelType.DM,
created_at: new Date(), created_at: new Date(),
}; };
await new ChannelModel(channel).save(); await new ChannelModel(channel).save();
/*Event({ event: "CHANNEL_CREATE", data: channel } as ChannelCreateEvent);*/ /*Event({ event: "CHANNEL_CREATE", data: channel } as ChannelCreateEvent);*/
res.json(channel); res.json(channel);
}); });

View File

@ -22,21 +22,13 @@ export const ChannelModifySchema = {
}; };
export const DmChannelCreateSchema = { export const DmChannelCreateSchema = {
owner_id: String, $name: String,
$id: String, recipients: [String],
$created_at: Date, };
name: String,
type: Number,
recipients: [String]
}
export interface DmChannelCreateSchema { export interface DmChannelCreateSchema {
owner_id: String; name?: string;
id?: String; recipients: string[];
created_at?: Date;
name: String;
type: Number;
recipients: String[];
} }
export interface ChannelModifySchema { export interface ChannelModifySchema {