chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously. closes #1282
This commit is contained in:
46
server/utils/removeIndexCollision.ts
Normal file
46
server/utils/removeIndexCollision.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import fractionalIndex from "fractional-index";
|
||||
import { Collection } from "@server/models";
|
||||
import { sequelize, Op } from "../sequelize";
|
||||
/**
|
||||
*
|
||||
* @param teamId The team id whose collections has to be fetched
|
||||
* @param index the index for which collision has to be checked
|
||||
* @returns An index, if there is collision returns a new index otherwise the same index
|
||||
*/
|
||||
|
||||
export default async function removeIndexCollision(
|
||||
teamId: string,
|
||||
index: string
|
||||
) {
|
||||
const collection = await Collection.findOne({
|
||||
where: {
|
||||
teamId,
|
||||
deletedAt: null,
|
||||
index,
|
||||
},
|
||||
});
|
||||
|
||||
if (!collection) {
|
||||
return index;
|
||||
}
|
||||
|
||||
const nextCollection = await Collection.findAll({
|
||||
where: {
|
||||
teamId,
|
||||
deletedAt: null,
|
||||
index: {
|
||||
[Op.gt]: index,
|
||||
},
|
||||
},
|
||||
attributes: ["id", "index"],
|
||||
limit: 1,
|
||||
order: [
|
||||
sequelize.literal('"collection"."index" collate "C"'),
|
||||
["updatedAt", "DESC"],
|
||||
],
|
||||
});
|
||||
const nextCollectionIndex = nextCollection.length
|
||||
? nextCollection[0].index
|
||||
: null;
|
||||
return fractionalIndex(index, nextCollectionIndex);
|
||||
}
|
||||
Reference in New Issue
Block a user