chore: Enable eslint to enforce curly (#3060)

This commit is contained in:
Tom Moor
2022-02-05 10:15:40 -08:00
committed by GitHub
parent c7df74fcc4
commit c5a11fe17b
103 changed files with 1175 additions and 397 deletions

View File

@@ -652,7 +652,9 @@ router.post("collections.delete", auth(), async (ctx) => {
authorize(user, "delete", collection);
const total = await Collection.count();
if (total === 1) throw ValidationError("Cannot delete last collection");
if (total === 1) {
throw ValidationError("Cannot delete last collection");
}
await collection.destroy();
await Event.create({

View File

@@ -50,7 +50,9 @@ router.post("documents.list", auth(), pagination(), async (ctx) => {
const collectionId = ctx.body.collectionId || ctx.body.collection;
const createdById = ctx.body.userId || ctx.body.user;
let direction = ctx.body.direction;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
// always filter by the current team
const { user } = ctx.state;
let where: WhereOptions<Document> = {
@@ -162,7 +164,9 @@ router.post("documents.archived", auth(), pagination(), async (ctx) => {
assertSort(sort, Document);
let direction = ctx.body.direction;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
const collectionIds = await user.collectionIds();
const collectionScope: Readonly<ScopeOptions> = {
@@ -204,7 +208,9 @@ router.post("documents.deleted", auth(), pagination(), async (ctx) => {
assertSort(sort, Document);
let direction = ctx.body.direction;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
const collectionIds = await user.collectionIds({
paranoid: false,
@@ -257,7 +263,9 @@ router.post("documents.viewed", auth(), pagination(), async (ctx) => {
const { sort = "updatedAt" } = ctx.body;
assertSort(sort, Document);
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
const collectionIds = await user.collectionIds();
const userId = user.id;
@@ -318,7 +326,9 @@ router.post("documents.starred", auth(), pagination(), async (ctx) => {
const { sort = "updatedAt" } = ctx.body;
assertSort(sort, Document);
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
const collectionIds = await user.collectionIds();
const stars = await Star.findAll({
@@ -371,7 +381,9 @@ router.post("documents.drafts", auth(), pagination(), async (ctx) => {
const { collectionId, dateFilter, sort = "updatedAt" } = ctx.body;
assertSort(sort, Document);
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
if (collectionId) {
@@ -997,7 +1009,9 @@ router.post("documents.update", auth(), async (ctx) => {
const editorVersion = ctx.headers["x-editor-version"] as string | undefined;
assertPresent(id, "id is required");
assertPresent(title || text, "title or text is required");
if (append) assertPresent(text, "Text is required while appending");
if (append) {
assertPresent(text, "Text is required while appending");
}
const { user } = ctx.state;
const document = await Document.findByPk(id, {
@@ -1012,10 +1026,18 @@ router.post("documents.update", auth(), async (ctx) => {
const previousTitle = document.title;
// Update document
if (title) document.title = title;
if (editorVersion) document.editorVersion = editorVersion;
if (templateId) document.templateId = templateId;
if (fullWidth !== undefined) document.fullWidth = fullWidth;
if (title) {
document.title = title;
}
if (editorVersion) {
document.editorVersion = editorVersion;
}
if (templateId) {
document.templateId = templateId;
}
if (fullWidth !== undefined) {
document.fullWidth = fullWidth;
}
if (!user.team?.collaborativeEditing) {
if (append) {
@@ -1303,7 +1325,9 @@ router.post("documents.import", auth(), async (ctx) => {
assertUuid(parentDocumentId, "parentDocumentId must be an uuid");
}
if (index) assertPositiveInteger(index, "index must be an integer (>=0)");
if (index) {
assertPositiveInteger(index, "index must be an integer (>=0)");
}
const { user } = ctx.state;
authorize(user, "createDocument", user.team);
@@ -1372,7 +1396,9 @@ router.post("documents.create", auth(), async (ctx) => {
assertUuid(parentDocumentId, "parentDocumentId must be an uuid");
}
if (index) assertPositiveInteger(index, "index must be an integer (>=0)");
if (index) {
assertPositiveInteger(index, "index must be an integer (>=0)");
}
const { user } = ctx.state;
authorize(user, "createDocument", user.team);

View File

@@ -20,7 +20,9 @@ router.post("events.list", auth(), pagination(), async (ctx) => {
name,
auditLog = false,
} = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, Event);
let where: WhereOptions<Event> = {

View File

@@ -42,7 +42,9 @@ router.post("fileOperations.list", auth(), pagination(), async (ctx) => {
"type must be one of 'import' or 'export'"
);
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
const { user } = ctx.state;
const where: WhereOptions<FileOperation> = {
teamId: user.teamId,

View File

@@ -19,7 +19,9 @@ const router = new Router();
router.post("groups.list", auth(), pagination(), async (ctx) => {
let { direction } = ctx.body;
const { sort = "updatedAt" } = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, Group);
const { user } = ctx.state;

View File

@@ -21,7 +21,9 @@ const router = new Router();
// triggered by a user posting a getoutline.com link in Slack
router.post("hooks.unfurl", async (ctx) => {
const { challenge, token, event } = ctx.body;
if (challenge) return (ctx.body = ctx.body.challenge);
if (challenge) {
return (ctx.body = ctx.body.challenge);
}
if (token !== process.env.SLACK_VERIFICATION_TOKEN) {
throw AuthenticationError("Invalid token");
@@ -39,21 +41,27 @@ router.post("hooks.unfurl", async (ctx) => {
},
],
});
if (!user) return;
if (!user) {
return;
}
const auth = await IntegrationAuthentication.findOne({
where: {
service: "slack",
teamId: user.teamId,
},
});
if (!auth) return;
if (!auth) {
return;
}
// get content for unfurled links
const unfurls = {};
for (const link of event.links) {
const id = link.url.substr(link.url.lastIndexOf("/") + 1);
const doc = await Document.findByPk(id);
if (!doc || doc.teamId !== user.teamId) continue;
if (!doc || doc.teamId !== user.teamId) {
continue;
}
unfurls[link.url] = {
title: doc.title,
text: doc.getSummary(),

View File

@@ -12,7 +12,9 @@ const router = new Router();
router.post("integrations.list", auth(), pagination(), async (ctx) => {
let { direction } = ctx.body;
const { sort = "updatedAt" } = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, Integration);
const { user } = ctx.state;

View File

@@ -33,7 +33,9 @@ router.post("revisions.info", auth(), async (ctx) => {
router.post("revisions.list", auth(), pagination(), async (ctx) => {
let { direction } = ctx.body;
const { documentId, sort = "updatedAt" } = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, Revision);
assertPresent(documentId, "documentId is required");

View File

@@ -100,7 +100,9 @@ router.post("shares.info", auth(), async (ctx) => {
router.post("shares.list", auth(), pagination(), async (ctx) => {
let { direction } = ctx.body;
const { sort = "updatedAt" } = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, Share);
const { user } = ctx.state;

View File

@@ -25,11 +25,21 @@ router.post("team.update", auth(), async (ctx) => {
team.subdomain = subdomain === "" ? null : subdomain;
}
if (name) team.name = name;
if (sharing !== undefined) team.sharing = sharing;
if (documentEmbeds !== undefined) team.documentEmbeds = documentEmbeds;
if (guestSignin !== undefined) team.guestSignin = guestSignin;
if (avatarUrl !== undefined) team.avatarUrl = avatarUrl;
if (name) {
team.name = name;
}
if (sharing !== undefined) {
team.sharing = sharing;
}
if (documentEmbeds !== undefined) {
team.documentEmbeds = documentEmbeds;
}
if (guestSignin !== undefined) {
team.guestSignin = guestSignin;
}
if (avatarUrl !== undefined) {
team.avatarUrl = avatarUrl;
}
if (collaborativeEditing !== undefined) {
team.collaborativeEditing = collaborativeEditing;

View File

@@ -20,7 +20,9 @@ const router = new Router();
router.post("users.list", auth(), pagination(), async (ctx) => {
let { direction } = ctx.body;
const { sort = "createdAt", query, filter } = ctx.body;
if (direction !== "ASC") direction = "DESC";
if (direction !== "ASC") {
direction = "DESC";
}
assertSort(sort, User);
if (filter) {
@@ -138,9 +140,15 @@ router.post("users.info", auth(), async (ctx) => {
router.post("users.update", auth(), async (ctx) => {
const { user } = ctx.state;
const { name, avatarUrl, language } = ctx.body;
if (name) user.name = name;
if (avatarUrl) user.avatarUrl = avatarUrl;
if (language) user.language = language;
if (name) {
user.name = name;
}
if (avatarUrl) {
user.avatarUrl = avatarUrl;
}
if (language) {
user.language = language;
}
await user.save();
await Event.create({
name: "users.update",