chore: Upgrade Prettier 1.8 -> 2.0 (#1436)
This commit is contained in:
@ -25,14 +25,14 @@ const ApiKey = sequelize.define(
|
||||
tableName: "apiKeys",
|
||||
paranoid: true,
|
||||
hooks: {
|
||||
beforeValidate: key => {
|
||||
beforeValidate: (key) => {
|
||||
key.secret = randomstring.generate(38);
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
ApiKey.associate = models => {
|
||||
ApiKey.associate = (models) => {
|
||||
ApiKey.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
|
@ -38,24 +38,24 @@ const Attachment = sequelize.define(
|
||||
},
|
||||
{
|
||||
getterMethods: {
|
||||
name: function() {
|
||||
name: function () {
|
||||
return path.parse(this.key).base;
|
||||
},
|
||||
redirectUrl: function() {
|
||||
redirectUrl: function () {
|
||||
return `/api/attachments.redirect?id=${this.id}`;
|
||||
},
|
||||
isPrivate: function() {
|
||||
isPrivate: function () {
|
||||
return this.acl === "private";
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Attachment.beforeDestroy(async model => {
|
||||
Attachment.beforeDestroy(async (model) => {
|
||||
await deleteFromS3(model.key);
|
||||
});
|
||||
|
||||
Attachment.associate = models => {
|
||||
Attachment.associate = (models) => {
|
||||
Attachment.belongsTo(models.Team);
|
||||
Attachment.belongsTo(models.Document);
|
||||
Attachment.belongsTo(models.User);
|
||||
|
@ -12,7 +12,7 @@ const Authentication = sequelize.define("authentication", {
|
||||
token: encryptedFields.vault("token"),
|
||||
});
|
||||
|
||||
Authentication.associate = models => {
|
||||
Authentication.associate = (models) => {
|
||||
Authentication.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
|
@ -9,7 +9,7 @@ const Backlink = sequelize.define("backlink", {
|
||||
},
|
||||
});
|
||||
|
||||
Backlink.associate = models => {
|
||||
Backlink.associate = (models) => {
|
||||
Backlink.belongsTo(models.Document, {
|
||||
as: "document",
|
||||
foreignKey: "documentId",
|
||||
|
@ -47,7 +47,7 @@ const Collection = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Collection.addHook("beforeSave", async model => {
|
||||
Collection.addHook("beforeSave", async (model) => {
|
||||
if (model.icon === "collection") {
|
||||
model.icon = null;
|
||||
}
|
||||
@ -55,7 +55,7 @@ Collection.addHook("beforeSave", async model => {
|
||||
|
||||
// Class methods
|
||||
|
||||
Collection.associate = models => {
|
||||
Collection.associate = (models) => {
|
||||
Collection.hasMany(models.Document, {
|
||||
as: "documents",
|
||||
foreignKey: "collectionId",
|
||||
@ -88,7 +88,7 @@ Collection.associate = models => {
|
||||
Collection.belongsTo(models.Team, {
|
||||
as: "team",
|
||||
});
|
||||
Collection.addScope("withMembership", userId => ({
|
||||
Collection.addScope("withMembership", (userId) => ({
|
||||
include: [
|
||||
{
|
||||
model: models.CollectionUser,
|
||||
@ -191,20 +191,20 @@ Collection.membershipUserIds = async (collectionId: string) => {
|
||||
);
|
||||
|
||||
const groupMemberships = collection.collectionGroupMemberships
|
||||
.map(cgm => cgm.group.groupMemberships)
|
||||
.map((cgm) => cgm.group.groupMemberships)
|
||||
.flat();
|
||||
|
||||
const membershipUserIds = concat(
|
||||
groupMemberships,
|
||||
collection.memberships
|
||||
).map(membership => membership.userId);
|
||||
).map((membership) => membership.userId);
|
||||
|
||||
return uniq(membershipUserIds);
|
||||
};
|
||||
|
||||
// Instance methods
|
||||
|
||||
Collection.prototype.addDocumentToStructure = async function(
|
||||
Collection.prototype.addDocumentToStructure = async function (
|
||||
document: Document,
|
||||
index: number,
|
||||
options = {}
|
||||
@ -237,8 +237,8 @@ Collection.prototype.addDocumentToStructure = async function(
|
||||
);
|
||||
} else {
|
||||
// Recursively place document
|
||||
const placeDocument = documentList => {
|
||||
return documentList.map(childDocument => {
|
||||
const placeDocument = (documentList) => {
|
||||
return documentList.map((childDocument) => {
|
||||
if (document.parentDocumentId === childDocument.id) {
|
||||
childDocument.children.splice(
|
||||
index !== undefined ? index : childDocument.children.length,
|
||||
@ -280,7 +280,7 @@ Collection.prototype.addDocumentToStructure = async function(
|
||||
/**
|
||||
* Update document's title and url in the documentStructure
|
||||
*/
|
||||
Collection.prototype.updateDocument = async function(
|
||||
Collection.prototype.updateDocument = async function (
|
||||
updatedDocument: Document
|
||||
) {
|
||||
if (!this.documentStructure) return;
|
||||
@ -293,8 +293,8 @@ Collection.prototype.updateDocument = async function(
|
||||
|
||||
const { id } = updatedDocument;
|
||||
|
||||
const updateChildren = documents => {
|
||||
return documents.map(document => {
|
||||
const updateChildren = (documents) => {
|
||||
return documents.map((document) => {
|
||||
if (document.id === id) {
|
||||
document = {
|
||||
...updatedDocument.toJSON(),
|
||||
@ -320,12 +320,12 @@ Collection.prototype.updateDocument = async function(
|
||||
return this;
|
||||
};
|
||||
|
||||
Collection.prototype.deleteDocument = async function(document) {
|
||||
Collection.prototype.deleteDocument = async function (document) {
|
||||
await this.removeDocumentInStructure(document);
|
||||
await document.deleteWithChildren();
|
||||
};
|
||||
|
||||
Collection.prototype.removeDocumentInStructure = async function(
|
||||
Collection.prototype.removeDocumentInStructure = async function (
|
||||
document,
|
||||
options
|
||||
) {
|
||||
@ -339,7 +339,7 @@ Collection.prototype.removeDocumentInStructure = async function(
|
||||
|
||||
const removeFromChildren = async (children, id) => {
|
||||
children = await Promise.all(
|
||||
children.map(async childDocument => {
|
||||
children.map(async (childDocument) => {
|
||||
return {
|
||||
...childDocument,
|
||||
children: await removeFromChildren(childDocument.children, id),
|
||||
|
@ -18,7 +18,7 @@ const CollectionGroup = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
CollectionGroup.associate = models => {
|
||||
CollectionGroup.associate = (models) => {
|
||||
CollectionGroup.belongsTo(models.Collection, {
|
||||
as: "collection",
|
||||
foreignKey: "collectionId",
|
||||
|
@ -17,7 +17,7 @@ const CollectionUser = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
CollectionUser.associate = models => {
|
||||
CollectionUser.associate = (models) => {
|
||||
CollectionUser.belongsTo(models.Collection, {
|
||||
as: "collection",
|
||||
foreignKey: "collectionId",
|
||||
|
@ -46,18 +46,18 @@ const createRevision = (doc, options = {}) => {
|
||||
);
|
||||
};
|
||||
|
||||
const createUrlId = doc => {
|
||||
const createUrlId = (doc) => {
|
||||
return (doc.urlId = doc.urlId || randomstring.generate(10));
|
||||
};
|
||||
|
||||
const beforeCreate = async doc => {
|
||||
const beforeCreate = async (doc) => {
|
||||
if (doc.version === undefined) {
|
||||
doc.version = DOCUMENT_VERSION;
|
||||
}
|
||||
return beforeSave(doc);
|
||||
};
|
||||
|
||||
const beforeSave = async doc => {
|
||||
const beforeSave = async (doc) => {
|
||||
const { emoji } = parseTitle(doc.text);
|
||||
|
||||
// emoji in the title is split out for easier display
|
||||
@ -123,7 +123,7 @@ const Document = sequelize.define(
|
||||
afterUpdate: createRevision,
|
||||
},
|
||||
getterMethods: {
|
||||
url: function() {
|
||||
url: function () {
|
||||
const slugifiedTitle = slugify(this.title);
|
||||
return `/doc/${slugifiedTitle}-${this.urlId}`;
|
||||
},
|
||||
@ -133,7 +133,7 @@ const Document = sequelize.define(
|
||||
|
||||
// Class methods
|
||||
|
||||
Document.associate = models => {
|
||||
Document.associate = (models) => {
|
||||
Document.belongsTo(models.Collection, {
|
||||
as: "collection",
|
||||
foreignKey: "collectionId",
|
||||
@ -185,7 +185,7 @@ Document.associate = models => {
|
||||
},
|
||||
},
|
||||
});
|
||||
Document.addScope("withCollection", userId => {
|
||||
Document.addScope("withCollection", (userId) => {
|
||||
if (userId) {
|
||||
return {
|
||||
include: [
|
||||
@ -209,19 +209,19 @@ Document.associate = models => {
|
||||
{ model: models.User, as: "updatedBy", paranoid: false },
|
||||
],
|
||||
});
|
||||
Document.addScope("withViews", userId => ({
|
||||
Document.addScope("withViews", (userId) => ({
|
||||
include: [
|
||||
{ model: models.View, as: "views", where: { userId }, required: false },
|
||||
],
|
||||
}));
|
||||
Document.addScope("withStarred", userId => ({
|
||||
Document.addScope("withStarred", (userId) => ({
|
||||
include: [
|
||||
{ model: models.Star, as: "starred", where: { userId }, required: false },
|
||||
],
|
||||
}));
|
||||
};
|
||||
|
||||
Document.findByPk = async function(id, options = {}) {
|
||||
Document.findByPk = async function (id, options = {}) {
|
||||
// allow default preloading of collection membership if `userId` is passed in find options
|
||||
// almost every endpoint needs the collection membership to determine policy permissions.
|
||||
const scope = this.scope("withUnpublished", {
|
||||
@ -322,7 +322,7 @@ Document.searchForTeam = async (
|
||||
],
|
||||
});
|
||||
|
||||
return map(results, result => ({
|
||||
return map(results, (result) => ({
|
||||
ranking: result.searchRanking,
|
||||
context: removeMarkdown(unescape(result.searchContext), {
|
||||
stripHTML: false,
|
||||
@ -424,7 +424,7 @@ Document.searchForUser = async (
|
||||
],
|
||||
});
|
||||
|
||||
return map(results, result => ({
|
||||
return map(results, (result) => ({
|
||||
ranking: result.searchRanking,
|
||||
context: removeMarkdown(unescape(result.searchContext), {
|
||||
stripHTML: false,
|
||||
@ -435,7 +435,7 @@ Document.searchForUser = async (
|
||||
|
||||
// Hooks
|
||||
|
||||
Document.addHook("beforeSave", async model => {
|
||||
Document.addHook("beforeSave", async (model) => {
|
||||
if (!model.publishedAt || model.template) {
|
||||
return;
|
||||
}
|
||||
@ -449,7 +449,7 @@ Document.addHook("beforeSave", async model => {
|
||||
model.collection = collection;
|
||||
});
|
||||
|
||||
Document.addHook("afterCreate", async model => {
|
||||
Document.addHook("afterCreate", async (model) => {
|
||||
if (!model.publishedAt || model.template) {
|
||||
return;
|
||||
}
|
||||
@ -467,7 +467,7 @@ Document.addHook("afterCreate", async model => {
|
||||
|
||||
// Instance methods
|
||||
|
||||
Document.prototype.toMarkdown = function() {
|
||||
Document.prototype.toMarkdown = function () {
|
||||
const text = unescape(this.text);
|
||||
|
||||
if (this.version) {
|
||||
@ -477,7 +477,7 @@ Document.prototype.toMarkdown = function() {
|
||||
return text;
|
||||
};
|
||||
|
||||
Document.prototype.migrateVersion = function() {
|
||||
Document.prototype.migrateVersion = function () {
|
||||
let migrated = false;
|
||||
|
||||
// migrate from document version 0 -> 1
|
||||
@ -505,13 +505,13 @@ Document.prototype.migrateVersion = function() {
|
||||
// Note: This method marks the document and it's children as deleted
|
||||
// in the database, it does not permanently delete them OR remove
|
||||
// from the collection structure.
|
||||
Document.prototype.deleteWithChildren = async function(options) {
|
||||
Document.prototype.deleteWithChildren = async function (options) {
|
||||
// Helper to destroy all child documents for a document
|
||||
const loopChildren = async (documentId, opts) => {
|
||||
const childDocuments = await Document.findAll({
|
||||
where: { parentDocumentId: documentId },
|
||||
});
|
||||
childDocuments.forEach(async child => {
|
||||
childDocuments.forEach(async (child) => {
|
||||
await loopChildren(child.id, opts);
|
||||
await child.destroy(opts);
|
||||
});
|
||||
@ -521,15 +521,15 @@ Document.prototype.deleteWithChildren = async function(options) {
|
||||
await this.destroy(options);
|
||||
};
|
||||
|
||||
Document.prototype.archiveWithChildren = async function(userId, options) {
|
||||
Document.prototype.archiveWithChildren = async function (userId, options) {
|
||||
const archivedAt = new Date();
|
||||
|
||||
// Helper to archive all child documents for a document
|
||||
const archiveChildren = async parentDocumentId => {
|
||||
const archiveChildren = async (parentDocumentId) => {
|
||||
const childDocuments = await Document.findAll({
|
||||
where: { parentDocumentId },
|
||||
});
|
||||
childDocuments.forEach(async child => {
|
||||
childDocuments.forEach(async (child) => {
|
||||
await archiveChildren(child.id);
|
||||
|
||||
child.archivedAt = archivedAt;
|
||||
@ -544,7 +544,7 @@ Document.prototype.archiveWithChildren = async function(userId, options) {
|
||||
return this.save(options);
|
||||
};
|
||||
|
||||
Document.prototype.publish = async function(options) {
|
||||
Document.prototype.publish = async function (options) {
|
||||
if (this.publishedAt) return this.save(options);
|
||||
|
||||
const collection = await Collection.findByPk(this.collectionId);
|
||||
@ -560,7 +560,7 @@ Document.prototype.publish = async function(options) {
|
||||
|
||||
// Moves a document from being visible to the team within a collection
|
||||
// to the archived area, where it can be subsequently restored.
|
||||
Document.prototype.archive = async function(userId) {
|
||||
Document.prototype.archive = async function (userId) {
|
||||
// archive any children and remove from the document structure
|
||||
const collection = await this.getCollection();
|
||||
await collection.removeDocumentInStructure(this);
|
||||
@ -572,7 +572,7 @@ Document.prototype.archive = async function(userId) {
|
||||
};
|
||||
|
||||
// Restore an archived document back to being visible to the team
|
||||
Document.prototype.unarchive = async function(userId) {
|
||||
Document.prototype.unarchive = async function (userId) {
|
||||
const collection = await this.getCollection();
|
||||
|
||||
// check to see if the documents parent hasn't been archived also
|
||||
@ -604,7 +604,7 @@ Document.prototype.unarchive = async function(userId) {
|
||||
};
|
||||
|
||||
// Delete a document, archived or otherwise.
|
||||
Document.prototype.delete = function(options) {
|
||||
Document.prototype.delete = function (options) {
|
||||
return sequelize.transaction(async (transaction: Transaction): Promise<*> => {
|
||||
if (!this.archivedAt) {
|
||||
// delete any children and remove from the document structure
|
||||
@ -623,11 +623,11 @@ Document.prototype.delete = function(options) {
|
||||
});
|
||||
};
|
||||
|
||||
Document.prototype.getTimestamp = function() {
|
||||
Document.prototype.getTimestamp = function () {
|
||||
return Math.round(new Date(this.updatedAt).getTime() / 1000);
|
||||
};
|
||||
|
||||
Document.prototype.getSummary = function() {
|
||||
Document.prototype.getSummary = function () {
|
||||
const plain = removeMarkdown(unescape(this.text), {
|
||||
stripHTML: false,
|
||||
});
|
||||
@ -641,7 +641,7 @@ Document.prototype.getSummary = function() {
|
||||
return notEmpty ? lines[1] : "";
|
||||
};
|
||||
|
||||
Document.prototype.toJSON = function() {
|
||||
Document.prototype.toJSON = function () {
|
||||
// Warning: only use for new documents as order of children is
|
||||
// handled in the collection's documentStructure
|
||||
return {
|
||||
|
@ -14,7 +14,7 @@ const Event = sequelize.define("event", {
|
||||
data: DataTypes.JSONB,
|
||||
});
|
||||
|
||||
Event.associate = models => {
|
||||
Event.associate = (models) => {
|
||||
Event.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
@ -37,14 +37,14 @@ Event.associate = models => {
|
||||
});
|
||||
};
|
||||
|
||||
Event.beforeCreate(event => {
|
||||
Event.beforeCreate((event) => {
|
||||
if (event.ip) {
|
||||
// cleanup IPV6 representations of IPV4 addresses
|
||||
event.ip = event.ip.replace(/^::ffff:/, "");
|
||||
}
|
||||
});
|
||||
|
||||
Event.afterCreate(event => {
|
||||
Event.afterCreate((event) => {
|
||||
events.add(event);
|
||||
});
|
||||
|
||||
|
@ -23,7 +23,7 @@ const Group = sequelize.define(
|
||||
timestamps: true,
|
||||
paranoid: true,
|
||||
validate: {
|
||||
isUniqueNameInTeam: async function() {
|
||||
isUniqueNameInTeam: async function () {
|
||||
const foundItem = await Group.findOne({
|
||||
where: {
|
||||
teamId: this.teamId,
|
||||
@ -39,7 +39,7 @@ const Group = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Group.associate = models => {
|
||||
Group.associate = (models) => {
|
||||
Group.hasMany(models.GroupUser, {
|
||||
as: "groupMemberships",
|
||||
foreignKey: "groupId",
|
||||
|
@ -10,7 +10,7 @@ const GroupUser = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
GroupUser.associate = models => {
|
||||
GroupUser.associate = (models) => {
|
||||
GroupUser.belongsTo(models.Group, {
|
||||
as: "group",
|
||||
foreignKey: "groupId",
|
||||
|
@ -13,7 +13,7 @@ const Integration = sequelize.define("integration", {
|
||||
events: DataTypes.ARRAY(DataTypes.STRING),
|
||||
});
|
||||
|
||||
Integration.associate = models => {
|
||||
Integration.associate = (models) => {
|
||||
Integration.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
|
@ -22,7 +22,7 @@ const Notification = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Notification.associate = models => {
|
||||
Notification.associate = (models) => {
|
||||
Notification.belongsTo(models.User, {
|
||||
as: "actor",
|
||||
foreignKey: "actorId",
|
||||
|
@ -29,26 +29,24 @@ const NotificationSetting = sequelize.define(
|
||||
timestamps: true,
|
||||
updatedAt: false,
|
||||
getterMethods: {
|
||||
unsubscribeUrl: function() {
|
||||
unsubscribeUrl: function () {
|
||||
const token = NotificationSetting.getUnsubscribeToken(this.userId);
|
||||
return `${process.env.URL}/api/notificationSettings.unsubscribe?token=${
|
||||
token
|
||||
}&id=${this.id}`;
|
||||
return `${process.env.URL}/api/notificationSettings.unsubscribe?token=${token}&id=${this.id}`;
|
||||
},
|
||||
unsubscribeToken: function() {
|
||||
unsubscribeToken: function () {
|
||||
return NotificationSetting.getUnsubscribeToken(this.userId);
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
NotificationSetting.getUnsubscribeToken = userId => {
|
||||
NotificationSetting.getUnsubscribeToken = (userId) => {
|
||||
const hash = crypto.createHash("sha256");
|
||||
hash.update(`${userId}-${process.env.SECRET_KEY}`);
|
||||
return hash.digest("hex");
|
||||
};
|
||||
|
||||
NotificationSetting.associate = models => {
|
||||
NotificationSetting.associate = (models) => {
|
||||
NotificationSetting.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
|
@ -21,7 +21,7 @@ const Revision = sequelize.define("revision", {
|
||||
backup: DataTypes.TEXT,
|
||||
});
|
||||
|
||||
Revision.associate = models => {
|
||||
Revision.associate = (models) => {
|
||||
Revision.belongsTo(models.Document, {
|
||||
as: "document",
|
||||
foreignKey: "documentId",
|
||||
@ -40,7 +40,7 @@ Revision.associate = models => {
|
||||
);
|
||||
};
|
||||
|
||||
Revision.prototype.migrateVersion = function() {
|
||||
Revision.prototype.migrateVersion = function () {
|
||||
let migrated = false;
|
||||
|
||||
// migrate from document version 0 -> 1
|
||||
|
@ -22,7 +22,7 @@ const Share = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Share.associate = models => {
|
||||
Share.associate = (models) => {
|
||||
Share.belongsTo(models.User, {
|
||||
as: "user",
|
||||
foreignKey: "userId",
|
||||
@ -44,7 +44,7 @@ Share.associate = models => {
|
||||
});
|
||||
};
|
||||
|
||||
Share.prototype.revoke = function(userId) {
|
||||
Share.prototype.revoke = function (userId) {
|
||||
this.revokedAt = new Date();
|
||||
this.revokedById = userId;
|
||||
return this.save();
|
||||
|
@ -9,7 +9,7 @@ const Star = sequelize.define("star", {
|
||||
},
|
||||
});
|
||||
|
||||
Star.associate = models => {
|
||||
Star.associate = (models) => {
|
||||
Star.belongsTo(models.Document);
|
||||
Star.belongsTo(models.User);
|
||||
};
|
||||
|
@ -83,13 +83,13 @@ const Team = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Team.associate = models => {
|
||||
Team.associate = (models) => {
|
||||
Team.hasMany(models.Collection, { as: "collections" });
|
||||
Team.hasMany(models.Document, { as: "documents" });
|
||||
Team.hasMany(models.User, { as: "users" });
|
||||
};
|
||||
|
||||
const uploadAvatar = async model => {
|
||||
const uploadAvatar = async (model) => {
|
||||
const endpoint = publicS3Endpoint();
|
||||
const { avatarUrl } = model;
|
||||
|
||||
@ -112,7 +112,7 @@ const uploadAvatar = async model => {
|
||||
}
|
||||
};
|
||||
|
||||
Team.prototype.provisionSubdomain = async function(subdomain) {
|
||||
Team.prototype.provisionSubdomain = async function (subdomain) {
|
||||
if (this.subdomain) return this.subdomain;
|
||||
|
||||
let append = 0;
|
||||
@ -129,7 +129,7 @@ Team.prototype.provisionSubdomain = async function(subdomain) {
|
||||
return subdomain;
|
||||
};
|
||||
|
||||
Team.prototype.provisionFirstCollection = async function(userId) {
|
||||
Team.prototype.provisionFirstCollection = async function (userId) {
|
||||
const collection = await Collection.create({
|
||||
name: "Welcome",
|
||||
description:
|
||||
@ -168,11 +168,11 @@ Team.prototype.provisionFirstCollection = async function(userId) {
|
||||
}
|
||||
};
|
||||
|
||||
Team.prototype.addAdmin = async function(user: User) {
|
||||
Team.prototype.addAdmin = async function (user: User) {
|
||||
return user.update({ isAdmin: true });
|
||||
};
|
||||
|
||||
Team.prototype.removeAdmin = async function(user: User) {
|
||||
Team.prototype.removeAdmin = async function (user: User) {
|
||||
const res = await User.findAndCountAll({
|
||||
where: {
|
||||
teamId: this.id,
|
||||
@ -190,7 +190,7 @@ Team.prototype.removeAdmin = async function(user: User) {
|
||||
}
|
||||
};
|
||||
|
||||
Team.prototype.suspendUser = async function(user: User, admin: User) {
|
||||
Team.prototype.suspendUser = async function (user: User, admin: User) {
|
||||
if (user.id === admin.id)
|
||||
throw new ValidationError("Unable to suspend the current user");
|
||||
return user.update({
|
||||
@ -199,20 +199,20 @@ Team.prototype.suspendUser = async function(user: User, admin: User) {
|
||||
});
|
||||
};
|
||||
|
||||
Team.prototype.activateUser = async function(user: User, admin: User) {
|
||||
Team.prototype.activateUser = async function (user: User, admin: User) {
|
||||
return user.update({
|
||||
suspendedById: null,
|
||||
suspendedAt: null,
|
||||
});
|
||||
};
|
||||
|
||||
Team.prototype.collectionIds = async function(paranoid: boolean = true) {
|
||||
Team.prototype.collectionIds = async function (paranoid: boolean = true) {
|
||||
let models = await Collection.findAll({
|
||||
attributes: ["id", "private"],
|
||||
where: { teamId: this.id, private: false },
|
||||
paranoid,
|
||||
});
|
||||
return models.map(c => c.id);
|
||||
return models.map((c) => c.id);
|
||||
};
|
||||
|
||||
Team.beforeSave(uploadAvatar);
|
||||
|
@ -59,7 +59,7 @@ const User = sequelize.define(
|
||||
);
|
||||
|
||||
// Class methods
|
||||
User.associate = models => {
|
||||
User.associate = (models) => {
|
||||
User.hasMany(models.ApiKey, { as: "apiKeys", onDelete: "cascade" });
|
||||
User.hasMany(models.NotificationSetting, {
|
||||
as: "notificationSettings",
|
||||
@ -71,7 +71,7 @@ User.associate = models => {
|
||||
};
|
||||
|
||||
// Instance methods
|
||||
User.prototype.collectionIds = async function(paranoid: boolean = true) {
|
||||
User.prototype.collectionIds = async function (paranoid: boolean = true) {
|
||||
const collectionStubs = await Collection.scope({
|
||||
method: ["withMembership", this.id],
|
||||
}).findAll({
|
||||
@ -82,15 +82,15 @@ User.prototype.collectionIds = async function(paranoid: boolean = true) {
|
||||
|
||||
return collectionStubs
|
||||
.filter(
|
||||
c =>
|
||||
(c) =>
|
||||
!c.private ||
|
||||
c.memberships.length > 0 ||
|
||||
c.collectionGroupMemberships.length > 0
|
||||
)
|
||||
.map(c => c.id);
|
||||
.map((c) => c.id);
|
||||
};
|
||||
|
||||
User.prototype.updateActiveAt = function(ip) {
|
||||
User.prototype.updateActiveAt = function (ip) {
|
||||
const fiveMinutesAgo = subMinutes(new Date(), 5);
|
||||
|
||||
// ensure this is updated only every few minutes otherwise
|
||||
@ -102,17 +102,17 @@ User.prototype.updateActiveAt = function(ip) {
|
||||
}
|
||||
};
|
||||
|
||||
User.prototype.updateSignedIn = function(ip) {
|
||||
User.prototype.updateSignedIn = function (ip) {
|
||||
this.lastSignedInAt = new Date();
|
||||
this.lastSignedInIp = ip;
|
||||
return this.save({ hooks: false });
|
||||
};
|
||||
|
||||
User.prototype.getJwtToken = function() {
|
||||
User.prototype.getJwtToken = function () {
|
||||
return JWT.sign({ id: this.id }, this.jwtSecret);
|
||||
};
|
||||
|
||||
User.prototype.getEmailSigninToken = function() {
|
||||
User.prototype.getEmailSigninToken = function () {
|
||||
if (this.service && this.service !== "email") {
|
||||
throw new Error("Cannot generate email signin token for OAuth user");
|
||||
}
|
||||
@ -123,7 +123,7 @@ User.prototype.getEmailSigninToken = function() {
|
||||
);
|
||||
};
|
||||
|
||||
const uploadAvatar = async model => {
|
||||
const uploadAvatar = async (model) => {
|
||||
const endpoint = publicS3Endpoint();
|
||||
const { avatarUrl } = model;
|
||||
|
||||
@ -147,7 +147,7 @@ const uploadAvatar = async model => {
|
||||
}
|
||||
};
|
||||
|
||||
const setRandomJwtSecret = model => {
|
||||
const setRandomJwtSecret = (model) => {
|
||||
model.jwtSecret = crypto.randomBytes(64).toString("hex");
|
||||
};
|
||||
|
||||
@ -179,7 +179,7 @@ const removeIdentifyingInfo = async (model, options) => {
|
||||
await model.save({ hooks: false, transaction: options.transaction });
|
||||
};
|
||||
|
||||
const checkLastAdmin = async model => {
|
||||
const checkLastAdmin = async (model) => {
|
||||
const teamId = model.teamId;
|
||||
|
||||
if (model.isAdmin) {
|
||||
@ -198,7 +198,7 @@ User.beforeDestroy(checkLastAdmin);
|
||||
User.beforeDestroy(removeIdentifyingInfo);
|
||||
User.beforeSave(uploadAvatar);
|
||||
User.beforeCreate(setRandomJwtSecret);
|
||||
User.afterCreate(async user => {
|
||||
User.afterCreate(async (user) => {
|
||||
const team = await Team.findByPk(user.teamId);
|
||||
|
||||
// From Slack support:
|
||||
|
@ -25,12 +25,12 @@ const View = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
View.associate = models => {
|
||||
View.associate = (models) => {
|
||||
View.belongsTo(models.Document);
|
||||
View.belongsTo(models.User);
|
||||
};
|
||||
|
||||
View.increment = async where => {
|
||||
View.increment = async (where) => {
|
||||
const [model, created] = await View.findOrCreate({ where });
|
||||
if (!created) {
|
||||
model.count += 1;
|
||||
@ -39,7 +39,7 @@ View.increment = async where => {
|
||||
return model;
|
||||
};
|
||||
|
||||
View.findByDocument = async documentId => {
|
||||
View.findByDocument = async (documentId) => {
|
||||
return View.findAll({
|
||||
where: { documentId },
|
||||
order: [["updatedAt", "DESC"]],
|
||||
@ -52,7 +52,7 @@ View.findByDocument = async documentId => {
|
||||
});
|
||||
};
|
||||
|
||||
View.findRecentlyEditingByDocument = async documentId => {
|
||||
View.findRecentlyEditingByDocument = async (documentId) => {
|
||||
return View.findAll({
|
||||
where: {
|
||||
documentId,
|
||||
|
@ -44,7 +44,7 @@ const models = {
|
||||
};
|
||||
|
||||
// based on https://github.com/sequelize/express-example/blob/master/models/index.js
|
||||
Object.keys(models).forEach(modelName => {
|
||||
Object.keys(models).forEach((modelName) => {
|
||||
if ("associate" in models[modelName]) {
|
||||
models[modelName].associate(models);
|
||||
}
|
||||
|
Reference in New Issue
Block a user