Feat: remove signature
This commit is contained in:
parent
983ad07932
commit
a4c80c73a6
|
|
@ -1,4 +1,4 @@
|
|||
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common';
|
||||
import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request';
|
||||
import { Organization } from '@prisma/client';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
|
@ -28,6 +28,14 @@ export class SignatureController {
|
|||
return this._signatureService.createOrUpdateSignature(org.id, body);
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
async deleteSignature(
|
||||
@GetOrgFromRequest() org: Organization,
|
||||
@Param('id') id: string
|
||||
) {
|
||||
return this._signatureService.deleteSignature(org.id, id);
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
async updateSignature(
|
||||
@Param('id') id: string,
|
||||
|
|
|
|||
|
|
@ -12,12 +12,14 @@ import { CopilotTextarea } from '@copilotkit/react-textarea';
|
|||
import { Select } from '@gitroom/react/form/select';
|
||||
import { useToaster } from '@gitroom/react/toaster/toaster';
|
||||
import { useT } from '@gitroom/react/translation/get.transation.service.client';
|
||||
import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';
|
||||
export const SignaturesComponent: FC<{
|
||||
appendSignature?: (value: string) => void;
|
||||
}> = (props) => {
|
||||
const { appendSignature } = props;
|
||||
const fetch = useFetch();
|
||||
const modal = useModals();
|
||||
const toaster = useToaster();
|
||||
const load = useCallback(async () => {
|
||||
return (await fetch('/signatures')).json();
|
||||
}, []);
|
||||
|
|
@ -36,6 +38,27 @@ export const SignaturesComponent: FC<{
|
|||
[mutate]
|
||||
);
|
||||
|
||||
const deleteSignature = useCallback(
|
||||
(data: any) => async () => {
|
||||
if (
|
||||
await deleteDialog(
|
||||
t(
|
||||
'are_you_sure_you_want_to_delete',
|
||||
`Are you sure you want to delete?`,
|
||||
{ name: data.content.slice(0, 15) + '...' }
|
||||
)
|
||||
)
|
||||
) {
|
||||
await fetch(`/signatures/${data.id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
mutate();
|
||||
toaster.show('Signature deleted successfully', 'success');
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const t = useT();
|
||||
|
||||
return (
|
||||
|
|
@ -92,7 +115,7 @@ export const SignaturesComponent: FC<{
|
|||
</div>
|
||||
<div className="flex justify-center">
|
||||
<div>
|
||||
<Button onClick={addSignature(p)}>
|
||||
<Button onClick={deleteSignature(p)}>
|
||||
{t('delete', 'Delete')}
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -45,4 +45,11 @@ export class SignatureRepository {
|
|||
|
||||
return { id: updatedId };
|
||||
}
|
||||
|
||||
deleteSignature(orgId: string, id: string) {
|
||||
return this._signatures.model.signatures.update({
|
||||
where: { id, organizationId: orgId },
|
||||
data: { deletedAt: new Date() },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,8 @@ export class SignatureService {
|
|||
id
|
||||
);
|
||||
}
|
||||
|
||||
deleteSignature(orgId: string, id: string) {
|
||||
return this._signatureRepository.deleteSignature(orgId, id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue