chore: upgrade sequelize (#965)

* 0.18.0

* chore: Upgrade sequelize 4 -> 5

* fix: migrations v5 support

* fix: Majority of test failures

* fix: the rest of v5 tests
This commit is contained in:
Tom Moor
2019-06-23 15:49:45 -07:00
committed by GitHub
parent 595adeb55f
commit 32f83311f6
35 changed files with 260 additions and 7662 deletions

View File

@@ -41,7 +41,7 @@ router.post('documents.list', auth(), pagination(), async ctx => {
ctx.assertUuid(collectionId, 'collection must be a UUID');
where = { ...where, collectionId };
const collection = await Collection.findById(collectionId);
const collection = await Collection.findByPk(collectionId);
authorize(user, 'read', collection);
// otherwise, filter by all collections the user has access to
@@ -77,7 +77,7 @@ router.post('documents.pinned', auth(), pagination(), async ctx => {
ctx.assertUuid(collectionId, 'collection is required');
const user = ctx.state.user;
const collection = await Collection.findById(collectionId);
const collection = await Collection.findByPk(collectionId);
authorize(user, 'read', collection);
const starredScope = { method: ['withStarred', user.id] };
@@ -86,7 +86,6 @@ router.post('documents.pinned', auth(), pagination(), async ctx => {
teamId: user.teamId,
collectionId,
pinnedById: {
// $FlowFixMe
[Op.ne]: null,
},
},
@@ -118,7 +117,6 @@ router.post('documents.archived', auth(), pagination(), async ctx => {
teamId: user.teamId,
collectionId: collectionIds,
archivedAt: {
// $FlowFixMe
[Op.ne]: null,
},
},
@@ -232,7 +230,6 @@ router.post('documents.drafts', auth(), pagination(), async ctx => {
where: {
userId: user.id,
collectionId: collectionIds,
// $FlowFixMe
publishedAt: { [Op.eq]: null },
},
order: [[sort, direction]],
@@ -258,9 +255,8 @@ router.post('documents.info', auth({ required: false }), async ctx => {
let document;
if (shareId) {
const share = await Share.find({
const share = await Share.findOne({
where: {
// $FlowFixMe
revokedAt: { [Op.eq]: null },
id: shareId,
},
@@ -277,7 +273,7 @@ router.post('documents.info', auth({ required: false }), async ctx => {
}
document = share.document;
} else {
document = await Document.findById(id);
document = await Document.findByPk(id);
authorize(user, 'read', document);
}
@@ -293,7 +289,7 @@ router.post('documents.revision', auth(), async ctx => {
ctx.assertPresent(id, 'id is required');
ctx.assertPresent(revisionId, 'revisionId is required');
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(ctx.state.user, 'read', document);
const revision = await Revision.findOne({
@@ -313,7 +309,7 @@ router.post('documents.revisions', auth(), pagination(), async ctx => {
let { id, sort = 'updatedAt', direction } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
ctx.assertPresent(id, 'id is required');
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(ctx.state.user, 'read', document);
@@ -335,7 +331,7 @@ router.post('documents.restore', auth(), async ctx => {
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
if (document.archivedAt) {
authorize(user, 'unarchive', document);
@@ -354,7 +350,7 @@ router.post('documents.restore', auth(), async ctx => {
// restore a document to a specific revision
authorize(user, 'update', document);
const revision = await Revision.findById(revisionId);
const revision = await Revision.findByPk(revisionId);
authorize(document, 'restore', revision);
document.text = revision.text;
@@ -386,7 +382,7 @@ router.post('documents.search', auth(), pagination(), async ctx => {
if (collectionId) {
ctx.assertUuid(collectionId, 'collectionId must be a UUID');
const collection = await Collection.findById(collectionId);
const collection = await Collection.findByPk(collectionId);
authorize(user, 'read', collection);
}
@@ -430,7 +426,7 @@ router.post('documents.pin', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'update', document);
@@ -454,7 +450,7 @@ router.post('documents.unpin', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'update', document);
@@ -478,7 +474,7 @@ router.post('documents.star', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'read', document);
@@ -499,7 +495,7 @@ router.post('documents.unstar', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'read', document);
@@ -590,7 +586,7 @@ router.post('documents.create', auth(), async ctx => {
// reload to get all of the data needed to present (user, collection etc)
// we need to specify publishedAt to bypass default scope that only returns
// published documents
document = await Document.find({
document = await Document.findOne({
where: { id: document.id, publishedAt: document.publishedAt },
});
@@ -615,7 +611,7 @@ router.post('documents.update', auth(), async ctx => {
if (append) ctx.assertPresent(text, 'Text is required while appending');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(ctx.state.user, 'update', document);
@@ -680,10 +676,10 @@ router.post('documents.move', auth(), async ctx => {
}
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'move', document);
const collection = await Collection.findById(collectionId);
const collection = await Collection.findByPk(collectionId);
authorize(user, 'update', collection);
if (collection.type !== 'atlas' && parentDocumentId) {
@@ -693,7 +689,7 @@ router.post('documents.move', auth(), async ctx => {
}
if (parentDocumentId) {
const parent = await Document.findById(parentDocumentId);
const parent = await Document.findByPk(parentDocumentId);
authorize(user, 'update', parent);
}
@@ -721,7 +717,7 @@ router.post('documents.archive', auth(), async ctx => {
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'archive', document);
await document.archive(user.id);
@@ -744,7 +740,7 @@ router.post('documents.delete', auth(), async ctx => {
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
const document = await Document.findByPk(id);
authorize(user, 'delete', document);
await document.delete();