diff --git a/package-lock.json b/package-lock.json index cef7a34124fb0a5ff521c3c2a76d42767a0f87e2..11c545e156bde2bd74eea3a46d4c84ceb99a37bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,8 +16,7 @@ "commander": "^12.0.0", "figlet": "^1.7.0", "inquirer": "^9.2.16", - "ts-node": "^10.9.2", - "tsc": "^2.0.4" + "ts-node": "^10.9.2" }, "devDependencies": { "@types/commander": "^2.12.2", @@ -5464,14 +5463,6 @@ } } }, - "node_modules/tsc": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz", - "integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==", - "bin": { - "tsc": "bin/tsc" - } - }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", diff --git a/package.json b/package.json index 41c03642815c3215dc9db73b316e3f7a75205f48..1017584c31d8cb1aff0df8ea3c0636602b7164cb 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,7 @@ "commander": "^12.0.0", "figlet": "^1.7.0", "inquirer": "^9.2.16", - "ts-node": "^10.9.2", - "tsc": "^2.0.4" + "ts-node": "^10.9.2" }, "devDependencies": { "@types/commander": "^2.12.2", diff --git a/src/features/association/createAssociation.ts b/src/features/association/createAssociation.ts index 3af3c0c358f9a89435bdc3581352d4108298c26a..bee813396e8fe442287de9b2dac7f7ff1232e99a 100644 --- a/src/features/association/createAssociation.ts +++ b/src/features/association/createAssociation.ts @@ -2,6 +2,11 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleCreateAssociation } from '../../handlers/association/associationHandlers.js' +/** + * Creates an association. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the association is created. + */ async function createAssociation (tezos: TezosToolkit): Promise<void> { await handleCreateAssociation(tezos).then(() => { console.log(chalk.bgGreenBright('\nVotre association a été créée !!')) diff --git a/src/features/association/joinAssociation.ts b/src/features/association/joinAssociation.ts index 5222356e876ef14cf7ad8e3aaf80638399db9205..47ab943e723d0d83b36214a46110158ae6195001 100644 --- a/src/features/association/joinAssociation.ts +++ b/src/features/association/joinAssociation.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetAssociations, handleJoinAssociation } from '../../handlers/association/associationHandlers.js' +/** + * Joins an association. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the user joins the association. + */ async function joinAssociation (tezos: TezosToolkit): Promise<void> { await handleGetAssociations(tezos).then(async (response) => { - const associationsByName: string[] = response + const associationsByName: string[] = response.map(association => association.name) await handleJoinAssociation(associationsByName, tezos).then(() => { console.log(chalk.bgGreenBright("\nVous avez rejoint l'association !!")) diff --git a/src/features/association/showAssociationDetails.ts b/src/features/association/showAssociationDetails.ts index dc5398797dcc916d57dba83461a0279a8418a7cd..9ec9d33e30ef3de612a3d9c8db69f31073fb6c59 100644 --- a/src/features/association/showAssociationDetails.ts +++ b/src/features/association/showAssociationDetails.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetAssociationDetails, handleGetAssociations } from '../../handlers/association/associationHandlers.js' +/** + * Displays details of association. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the association details are displayed. + */ async function showAssociationDetails (tezos: TezosToolkit): Promise<void> { await handleGetAssociations(tezos).then(async (response) => { - const associationsByName = response + const associationsByName = response.map(association => association.name) if (response.length === 0) throw new Error('Aucune association existante') diff --git a/src/features/association/showAssociations.ts b/src/features/association/showAssociations.ts index 74e24adeefad0dad1a15317ffedc6f8b0ae0ef89..751c3205fe30ed5f1ef46543c9ff46a94eac0b62 100644 --- a/src/features/association/showAssociations.ts +++ b/src/features/association/showAssociations.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetAssociations } from '../../handlers/association/associationHandlers.js' +/** + * Displays associations. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the associations are displayed. + */ async function showAssociations (tezos: TezosToolkit): Promise<void> { await handleGetAssociations(tezos).then((response) => { - const associationsByName = response + const associationsByName = response.map(association => association.name) if (response.length === 0) throw new Error('Aucune association existante') diff --git a/src/features/balance/showBalance.ts b/src/features/balance/showBalance.ts index 91057fe7e087dcb7d712cce01163fa07574daf5f..764688eda36619577dd13983acbd8b5e62f70772 100644 --- a/src/features/balance/showBalance.ts +++ b/src/features/balance/showBalance.ts @@ -2,6 +2,11 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetBalance } from '../../handlers/balance/balanceHandlers.js' +/** + * Displays the balance of the wallet. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the balance is displayed. + */ async function showBalance (tezos: TezosToolkit): Promise<void> { await handleGetBalance(tezos).then((response) => { console.log(`\nSolde du portefeuille: ${response} ꜩ`) diff --git a/src/features/proposal/closeProposal.ts b/src/features/proposal/closeProposal.ts index 4a0743f95938e96f576940311e1a45fff9cb880e..0a69fc911273f420ad7aa4a4158410aea9662e0d 100644 --- a/src/features/proposal/closeProposal.ts +++ b/src/features/proposal/closeProposal.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetOpenProposals, handleCloseProposal } from '../../handlers/proposal/proposalHandlers.js' +/** + * Closes a proposal + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the proposal is closed. + */ async function closeProposal (tezos: TezosToolkit): Promise<void> { await handleGetOpenProposals(tezos).then(async (response) => { - const proposalsByTitle: string[] = response + const proposalsByTitle: string[] = response.map(proposal => proposal.title) if (response.length === 0) throw new Error("Aucune proposition n'est ouverte") diff --git a/src/features/proposal/createProposal.ts b/src/features/proposal/createProposal.ts index 0056904fe478ab9b6dbad915623454e83e5150da..1e3323185e3167b4854250e965f16cffbf9383d5 100644 --- a/src/features/proposal/createProposal.ts +++ b/src/features/proposal/createProposal.ts @@ -2,6 +2,11 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleCreateProposal } from '../../handlers/proposal/proposalHandlers.js' +/** + * Creates a proposal. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the proposal is created. + */ async function createProposal (tezos: TezosToolkit): Promise<void> { await handleCreateProposal(tezos).then(() => { console.log(chalk.bgGreenBright('\nVous avez soumis une proposition !!')) diff --git a/src/features/proposal/resolveProposal.ts b/src/features/proposal/resolveProposal.ts index a61360ecefdabe76c9420b01ee81037cf6edcaaa..6e2c1aba1fa7b58a3e3a5434e301bd486d6fddd3 100644 --- a/src/features/proposal/resolveProposal.ts +++ b/src/features/proposal/resolveProposal.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetSolvableProposals, handleResolveProposal } from '../../handlers/proposal/proposalHandlers.js' +/** + * Resolves a proposal. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the proposal is resolved. + */ async function resolveProposal (tezos: TezosToolkit): Promise<void> { await handleGetSolvableProposals(tezos).then(async (response) => { - const proposalsByTitle: string[] = response + const proposalsByTitle: string[] = response.map(proposal => proposal.title) if (response.length === 0) throw new Error("Aucune proposition n'est résoluble") diff --git a/src/features/proposal/showProposals.ts b/src/features/proposal/showProposals.ts index c85dda0a84edd6929aa44841934a75b2856229cc..3336cb544da43babd5ebc42f67aea831de246536 100644 --- a/src/features/proposal/showProposals.ts +++ b/src/features/proposal/showProposals.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetProposals } from '../../handlers/proposal/proposalHandlers.js' +/** + * Displays proposals. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the proposals are displayed. + */ async function showProposals (tezos: TezosToolkit): Promise<void> { await handleGetProposals(tezos).then((response) => { - const proposalsByTitle = response + const proposalsByTitle = response.map(proposal => proposal.title) if (response.length === 0) throw new Error('Aucune proposition existante') diff --git a/src/features/proposal/voteProposal.ts b/src/features/proposal/voteProposal.ts index fd6ec9e4c50260d25f6e827eeb107245638aac3f..cdd10197c553b929d0040fb2853b7f110b03111e 100644 --- a/src/features/proposal/voteProposal.ts +++ b/src/features/proposal/voteProposal.ts @@ -2,9 +2,14 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleGetOpenProposals, handleVoteProposal } from '../../handlers/proposal/proposalHandlers.js' +/** + * Votes for a proposal. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the vote is submitted. + */ async function voteProposal (tezos: TezosToolkit): Promise<void> { await handleGetOpenProposals(tezos).then(async (response) => { - const proposalsByTitle: string[] = response + const proposalsByTitle: string[] = response.map(proposal => proposal.title) if (response.length === 0) throw new Error("Aucune proposition n'est ouverte") diff --git a/src/features/token/burnToken.ts b/src/features/token/burnToken.ts index e301093feefbf85904a78b1f495bb646cd185c96..98060c4a21d8e299c5880539a76ed42dc1493eb5 100644 --- a/src/features/token/burnToken.ts +++ b/src/features/token/burnToken.ts @@ -2,6 +2,11 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleBurnToken } from '../../handlers/token/tokenHandlers.js' +/** + * Burns tokens. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the tokens are burned. + */ async function burnToken (tezos: TezosToolkit): Promise<void> { await handleBurnToken(tezos).then(() => { console.log(chalk.bgGreenBright('\nVous avez bruler vos tokens !!')) diff --git a/src/features/token/createToken.ts b/src/features/token/createToken.ts index 478106f5911ff5226df1b08f64d5f17f6f3664cb..cf6911345e179acc93df24a1505e65b4ea085966 100644 --- a/src/features/token/createToken.ts +++ b/src/features/token/createToken.ts @@ -2,6 +2,11 @@ import { type TezosToolkit } from '@taquito/taquito' import chalk from 'chalk' import { handleCreateToken } from '../../handlers/token/tokenHandlers.js' +/** + * Creates a token. + * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. + * @returns {Promise<void>} A promise resolved once the token is created. + */ async function createToken (tezos: TezosToolkit): Promise<void> { await handleCreateToken(tezos).then(() => { console.log(chalk.bgGreenBright('\nVotre token a été créé !!')) diff --git a/src/handlers/association/associationHandlers.ts b/src/handlers/association/associationHandlers.ts index f7f4db3fe6c48d7fe4e02bb85f6b172d049591c6..431f061fd7b80d0d6d94671ce577ef7e74ccb201 100644 --- a/src/handlers/association/associationHandlers.ts +++ b/src/handlers/association/associationHandlers.ts @@ -95,12 +95,11 @@ async function handleJoinAssociation (associations: string[], tezos: TezosToolki /** * Handles the process of listing associations. * @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations. - * @returns {Promise<string[]>} A promise with a list of string of association name. + * @returns {Promise<Association[]>} A promise with a list of string of association name. */ -async function handleGetAssociations (tezos: TezosToolkit): Promise<string[]> { +async function handleGetAssociations (tezos: TezosToolkit): Promise<Association[]> { try { - const associations = await getAssociations(tezos) - return associations.map(association => association.name) + return await getAssociations(tezos) } catch (error) { const errorMessage = error.message ? error.message : 'Unknown error occurred' throw new Error(`${errorMessage}`) diff --git a/src/handlers/proposal/proposalHandlers.ts b/src/handlers/proposal/proposalHandlers.ts index 6e92e1a754923b7215463d59ea3cff51f78f44db..9b85ebdd9355ae222abeb962e147ef70376c3f13 100644 --- a/src/handlers/proposal/proposalHandlers.ts +++ b/src/handlers/proposal/proposalHandlers.ts @@ -128,10 +128,9 @@ async function handleCloseProposal (proposals: string[], tezos: TezosToolkit): P * @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations. * @returns {Promise<Proposal[]>} A promise with a list of proposal title. */ -async function handleGetProposals (tezos: TezosToolkit): Promise<string[]> { +async function handleGetProposals (tezos: TezosToolkit): Promise<Proposal[]> { try { - const proposals: Proposal[] = await getProposals(tezos) - return proposals.map(proposal => proposal.title) + return await getProposals(tezos) } catch (error) { const errorMessage = error.message ? error.message : 'Unknown error occurred' throw new Error(`${errorMessage}`) @@ -141,12 +140,12 @@ async function handleGetProposals (tezos: TezosToolkit): Promise<string[]> { /** * Handles the process of listing open proposals. * @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations. - * @returns {Promise<string[]>} A promise with a list of open proposal title. + * @returns {Promise<Proposal[]>} A promise with a list of open proposal title. */ -async function handleGetOpenProposals (tezos: TezosToolkit): Promise<string[]> { +async function handleGetOpenProposals (tezos: TezosToolkit): Promise<Proposal[]> { try { const proposals: Proposal[] = await getProposals(tezos) - return proposals.filter(proposal => proposal.isOpen).map(proposal => proposal.title) + return proposals.filter(proposal => proposal.isOpen) } catch (error) { const errorMessage = error.message ? error.message : 'Unknown error occurred' throw new Error(`${errorMessage}`) @@ -156,12 +155,12 @@ async function handleGetOpenProposals (tezos: TezosToolkit): Promise<string[]> { /** * Handles the process of listing solvable proposals. * @param {TezosToolkit} tezos - The TezosToolkit instance used for blockchain operations. - * @returns {Promise<string[]>} A promise with a list of solvable proposal title. + * @returns {Promise<Proposal[]>} A promise with a list of solvable proposal title. */ -async function handleGetSolvableProposals (tezos: TezosToolkit): Promise<string[]> { +async function handleGetSolvableProposals (tezos: TezosToolkit): Promise<Proposal[]> { try { const proposals: Proposal[] = await getProposals(tezos) - return proposals.filter(proposal => proposal.approveRate >= 51).map(proposal => proposal.title) + return proposals.filter(proposal => proposal.approveRate >= 51) } catch (error) { const errorMessage = error.message ? error.message : 'Unknown error occurred' throw new Error(`${errorMessage}`) diff --git a/src/utils/getRole.ts b/src/utils/getRole.ts index d6de12fa4f7caaafe08aa2486790b3cb0ece1098..ea17ad81e7f32debbfa4bf5f6f0d993651a92259 100644 --- a/src/utils/getRole.ts +++ b/src/utils/getRole.ts @@ -8,5 +8,5 @@ export async function getRole (tezos: TezosToolkit): Promise<Role> { // if (isAdmin) return 'ADMIN' // TEMPORARY - return 'CONNECTED' + return 'ADHERENT' } diff --git a/test/handlers/association/associationHandlers.spec.ts b/test/handlers/association/associationHandlers.spec.ts index fa5210c31ec027ee61bb6b226f4f95d19f3ccd75..1b5b1d374bf2f18c77bc7bb12c65e5ca57745dc2 100644 --- a/test/handlers/association/associationHandlers.spec.ts +++ b/test/handlers/association/associationHandlers.spec.ts @@ -131,8 +131,14 @@ describe('associationHandlers', () => { expect(getAssociationsSpy).toBeCalledWith(mockedTezosToolkit) expect(associations).toStrictEqual( [ - 'Association 1', - 'Association 2' + { + description: 'Association 1 description', + name: 'Association 1' + }, + { + description: 'Association 2 description', + name: 'Association 2' + } ] ) }) diff --git a/test/handlers/proposal/proposalHandlers.spec.ts b/test/handlers/proposal/proposalHandlers.spec.ts index 7785c335dc6648f35efa2d82dfaeacca7e18c6d1..e7115cda791262622dfe3e4618a174bf5c9b5463 100644 --- a/test/handlers/proposal/proposalHandlers.spec.ts +++ b/test/handlers/proposal/proposalHandlers.spec.ts @@ -159,8 +159,14 @@ describe('proposalHandlers', () => { expect(getProposalsSpy).toBeCalledWith(mockedTezosToolkit) expect(proposals).toStrictEqual( [ - 'Proposal 1', - 'Proposal 2' + { + description: 'Proposal 1 description', + title: 'Proposal 1' + }, + { + description: 'Proposal 2 description', + title: 'Proposal 2' + } ] ) }) @@ -198,7 +204,11 @@ describe('proposalHandlers', () => { expect(getProposalsSpy).toBeCalledWith(mockedTezosToolkit) expect(proposals).toStrictEqual( [ - 'Proposal 1' + { + description: 'Proposal 1 description', + isOpen: true, + title: 'Proposal 1' + } ] ) }) @@ -236,7 +246,11 @@ describe('proposalHandlers', () => { expect(getProposalsSpy).toBeCalledWith(mockedTezosToolkit) expect(proposals).toStrictEqual( [ - 'Proposal 2' + { + approveRate: 51, + description: 'Proposal 2 description', + title: 'Proposal 2' + } ] ) })