From 3fdfbdc35b8a246f69eddd8ebdecf007a2b29ad7 Mon Sep 17 00:00:00 2001 From: Lautaro Petaccio Date: Fri, 13 Oct 2023 16:53:21 -0300 Subject: [PATCH] fix: Remove uuid usage --- src/entities/Proposal/testHelpers.ts | 4 ++-- src/entities/QuarterBudget/model.ts | 4 ++-- src/entities/Updates/model.test.ts | 6 ++---- src/entities/Updates/model.ts | 6 +++--- src/entities/Updates/utils.test.ts | 6 +++--- src/services/BadgesService.ts | 4 ++-- src/services/ProposalService.ts | 4 ++-- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/entities/Proposal/testHelpers.ts b/src/entities/Proposal/testHelpers.ts index c4d693541..391fdc855 100644 --- a/src/entities/Proposal/testHelpers.ts +++ b/src/entities/Proposal/testHelpers.ts @@ -1,6 +1,6 @@ // eslint-disable @typescript-eslint/no-explicit-any +import crypto from 'crypto' import JobContext from 'decentraland-gatsby/dist/entities/Job/context' -import { v1 as uuid } from 'uuid' import Time from '../../utils/date/Time' import { Budget } from '../Budget/types' @@ -103,7 +103,7 @@ export function createTestProposal( grantCategory?: NewGrantCategory ): ProposalAttributes { const testProposalConfiguration = getTestProposalConfiguration(proposalType, grantSize, grantCategory) - const id = uuid() + const id = crypto.randomUUID() return { ...BASIC_ATTRIBUTES, id: `id-${proposalType.toString()}-${proposalStatus.toString()}-${id}`, diff --git a/src/entities/QuarterBudget/model.ts b/src/entities/QuarterBudget/model.ts index 73103862b..db0b247c4 100644 --- a/src/entities/QuarterBudget/model.ts +++ b/src/entities/QuarterBudget/model.ts @@ -1,7 +1,7 @@ +import crypto from 'crypto' import { Model } from 'decentraland-gatsby/dist/entities/Database/model' import { SQL, table } from 'decentraland-gatsby/dist/entities/Database/utils' import snakeCase from 'lodash/snakeCase' -import { v1 as uuid } from 'uuid' import { TransparencyBudget } from '../../clients/DclData' import Time from '../../utils/date/Time' @@ -61,7 +61,7 @@ export default class QuarterBudgetModel extends Model { private static getNewQuarterBudget(transparencyBudget: TransparencyBudget, startAt: Date, finishAt: Date, now: Date) { const newQuarterBudget: QuarterBudgetAttributes = { - id: uuid(), + id: crypto.randomUUID(), total: transparencyBudget.total, start_at: startAt, finish_at: finishAt, diff --git a/src/entities/Updates/model.test.ts b/src/entities/Updates/model.test.ts index 13dc2b3a9..bc314e3b7 100644 --- a/src/entities/Updates/model.test.ts +++ b/src/entities/Updates/model.test.ts @@ -1,5 +1,5 @@ import { def } from 'bdd-lazy-var/getter' -import * as uuid from 'uuid' +import crypto from 'crypto' import Time from '../../utils/date/Time' import { getMonthsBetweenDates } from '../../utils/date/getMonthsBetweenDates' @@ -8,8 +8,6 @@ import { VestingStartDate } from '../Grant/types' import UpdateModel from './model' import { UpdateStatus } from './types' -jest.mock('uuid') - const PROPOSAL_ID = '123' const UUID = '00000000-0000-0000-0000-000000000000' @@ -20,7 +18,7 @@ describe('UpdateModel', () => { jest.clearAllMocks() jest.spyOn(UpdateModel, 'createMany').mockImplementation((list: any) => list) jest.spyOn(UpdateModel, 'delete').mockResolvedValue([] as any) - jest.spyOn(uuid, 'v1').mockReturnValue(UUID) + jest.spyOn(crypto, 'randomUUID').mockReturnValue(UUID) jest.useFakeTimers('modern') jest.setSystemTime(FAKE_NOW) }) diff --git a/src/entities/Updates/model.ts b/src/entities/Updates/model.ts index 068829cc6..cacf78d13 100644 --- a/src/entities/Updates/model.ts +++ b/src/entities/Updates/model.ts @@ -1,5 +1,5 @@ +import crypto from 'crypto' import { Model } from 'decentraland-gatsby/dist/entities/Database/model' -import { v1 as uuid } from 'uuid' import { VestingDates } from '../../clients/VestingData' import Time from '../../utils/date/Time' @@ -31,7 +31,7 @@ export default class UpdateModel extends Model { const updates = Array.from(Array(updatesQuantity), (_, index) => { const update: UpdateAttributes = { - id: uuid(), + id: crypto.randomUUID(), proposal_id: proposalId, status: UpdateStatus.Pending, due_date: this.getDueDate(firstUpdateStartingDate, index), @@ -68,7 +68,7 @@ export default class UpdateModel extends Model { const now = new Date() return await this.create({ - id: uuid(), + id: crypto.randomUUID(), status: UpdateStatus.Done, due_date: undefined, completion_date: now, diff --git a/src/entities/Updates/utils.test.ts b/src/entities/Updates/utils.test.ts index ae1323d69..e84b06bc5 100644 --- a/src/entities/Updates/utils.test.ts +++ b/src/entities/Updates/utils.test.ts @@ -1,4 +1,4 @@ -import { v1 as uuid } from 'uuid' +import crypto from 'crypto' import Time from '../../utils/date/Time' @@ -20,8 +20,8 @@ type GenerateUpdate = Pick< | 'completion_date' > const generateUpdate = (update: GenerateUpdate): UpdateAttributes => ({ - id: uuid(), - proposal_id: uuid(), + id: crypto.randomUUID(), + proposal_id: crypto.randomUUID(), health: update.health, introduction: update.introduction, highlights: update.highlights, diff --git a/src/services/BadgesService.ts b/src/services/BadgesService.ts index bbece0027..ad9344b96 100644 --- a/src/services/BadgesService.ts +++ b/src/services/BadgesService.ts @@ -1,5 +1,5 @@ +import crypto from 'crypto' import logger from 'decentraland-gatsby/dist/entities/Development/logger' -import { v1 as uuid } from 'uuid' import AirdropJobModel from '../back/models/AirdropJob' import { VoteService } from '../back/services/vote' @@ -177,7 +177,7 @@ export class BadgesService { private static async queueAirdropJob(badgeSpec: string, recipients: string[]) { logger.log(`Enqueueing airdrop job`, { badgeSpec, recipients }) try { - await AirdropJobModel.create({ id: uuid(), badge_spec: badgeSpec, recipients }) + await AirdropJobModel.create({ id: crypto.randomUUID(), badge_spec: badgeSpec, recipients }) } catch (error) { ErrorService.report('Unable to create AirdropJob', { error, diff --git a/src/services/ProposalService.ts b/src/services/ProposalService.ts index 8d7577914..bf3f4e6f5 100644 --- a/src/services/ProposalService.ts +++ b/src/services/ProposalService.ts @@ -1,6 +1,6 @@ +import crypto from 'crypto' import logger from 'decentraland-gatsby/dist/entities/Development/logger' import RequestError from 'decentraland-gatsby/dist/entities/Route/error' -import { v1 as uuid } from 'uuid' import { VoteService } from '../back/services/vote' import { Discourse, DiscourseComment, DiscoursePost } from '../clients/Discourse' @@ -44,7 +44,7 @@ export class ProposalService { throw new Error('Decentraland DAO Grants Program has been put on hold') } - const proposalId = uuid() + const proposalId = crypto.randomUUID() const proposalLifespan = this.getLifespan(proposalInCreation) const coAuthors = this.getCoAuthors(proposalInCreation)