-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/app/src/app/(default)/index-egapro/declaration/[siren]/[year]/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use server"; | ||
import { entrepriseService } from "@api/core-domain/infra/services"; | ||
import { declarationRepo } from "@api/core-domain/repo"; | ||
import { SaveDeclaration } from "@api/core-domain/useCases/SaveDeclaration"; | ||
import { assertServerSession } from "@api/utils/auth"; | ||
import { DeclarationSpecificationError } from "@common/core-domain/domain/specification/DeclarationSpecification"; | ||
import { Siren } from "@common/core-domain/domain/valueObjects/Siren"; | ||
import { type CreateDeclarationDTO } from "@common/core-domain/dtos/DeclarationDTO"; | ||
import { ValidationError } from "@common/shared-domain"; | ||
import { PositiveNumber } from "@common/shared-domain/domain/valueObjects"; | ||
import { type ServerActionResponse } from "@common/utils/next"; | ||
|
||
export async function updateCompanyInfos( | ||
declaration: CreateDeclarationDTO, | ||
oldSiren: string | undefined, | ||
): Promise<ServerActionResponse<undefined, string>> { | ||
const session = await assertServerSession({ | ||
owner: { | ||
check: declaration.commencer?.siren || "", | ||
message: "Not authorized to save declaration for this Siren.", | ||
}, | ||
staff: true, | ||
}); | ||
|
||
try { | ||
const useCase = new SaveDeclaration(declarationRepo, entrepriseService); | ||
await useCase.execute({ declaration, override: session?.user?.staff }); | ||
if (oldSiren && declaration.commencer?.annéeIndicateurs) | ||
await declarationRepo.delete([new Siren(oldSiren), new PositiveNumber(declaration.commencer?.annéeIndicateurs)]); | ||
|
||
return { | ||
ok: true, | ||
}; | ||
} catch (error: unknown) { | ||
if (error instanceof DeclarationSpecificationError || error instanceof ValidationError) { | ||
return { | ||
ok: false, | ||
error: error.message ?? error.previousError, | ||
}; | ||
} | ||
return { | ||
ok: false, | ||
error: "Une erreur est survenue, veuillez réessayer.", | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters