Remove unnecessary logic from removeIndexCollisions

This commit is contained in:
Saumya Pandey committed 2021-03-15 17:25:32 +05:30
1 parent d6a494910f
commit 41c84a92cd
1 file changed
+10 -22
+10 -22
View File
@@ -6,25 +6,17 @@ import { sequelize } from "../sequelize";
/**
*
* @param teamId The team id whose collections has to be fetched
* @param index All collections with given index value are given new index value
* @param collections If collections is passed, this is used to form collections array and no db query is made
* @returns An array of collided collections or undefined.If array, rach array element is an array of collection id and its new index [id,newIndex]
* @returns An array or undefined. If array, each array element is an array of collided collection id and its new index [id,newIndex]
*/
export default async function removeIndexCollisions(
teamId: string,
index?: string,
collections?: Collection[]
) {
if (!collections) {
collections = await Collection.findAll({
where: { teamId, deletedAt: null },
attributes: ["id", "index", "updatedAt"],
order: [
sequelize.literal('"collection"."index" collate "C"'),
["updatedAt", "DESC"],
],
});
}
export default async function removeIndexCollisions(teamId: string) {
let collections = await Collection.findAll({
where: { teamId, deletedAt: null },
attributes: ["id", "index", "updatedAt"],
order: [
sequelize.literal('"collection"."index" collate "C"'),
["updatedAt", "DESC"],
],
});
collections = collections.map((collection) => {
return [collection, collection.index];
@@ -33,10 +25,6 @@ export default async function removeIndexCollisions(
// a set to store the index value of collections.
const indexSet = new Set();
if (index) {
indexSet.add(index);
}
let collision = false;
// make the index null, if there is index collision