diff --git a/shared/types/src/elastic/common.ts b/shared/types/src/elastic/common.ts index 46e4229f3..e1a922c3c 100644 --- a/shared/types/src/elastic/common.ts +++ b/shared/types/src/elastic/common.ts @@ -1,4 +1,5 @@ import { SourceRoute } from "@socialgouv/cdtn-sources"; +import { ContributionsAnswers } from "../hasura"; export type DocumentElasticWithSource< T, @@ -11,6 +12,11 @@ export type Breadcrumb = { slug: string; }; +export type Export = { + id: string; + createdAt: string; +}; + export type DocumentElastic = { id: string; cdtnId: string; @@ -23,6 +29,8 @@ export type DocumentElastic = { excludeFromSearch: boolean; metaDescription: string; refs: DocumentRef[]; + contribution?: ContributionsAnswers; + export?: Export; }; export type RelatedDocument = { diff --git a/shared/types/src/hasura/contributions.ts b/shared/types/src/hasura/contributions.ts index dd520227f..a8c2e52eb 100644 --- a/shared/types/src/hasura/contributions.ts +++ b/shared/types/src/hasura/contributions.ts @@ -1,6 +1,11 @@ import { HasuraDocument } from "./common"; import { FicheServicePublicDoc } from "./fiche-sp"; +export type ContributionStatus = { + createdAt: string; + status: string; +}; + export type ContributionsAnswers = { id: string; content: string | null; @@ -14,6 +19,8 @@ export type ContributionsAnswers = { content_fiche_sp: ContributionContentFicheSp | null; message_block_generic_no_CDT: string | null; agreement: ContributionAgreement; + updatedAt: string; + statuses?: ContributionStatus[]; }; export type ContributionQuestion = { diff --git a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts index 2f09f4b78..c3f09e15f 100644 --- a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts +++ b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts @@ -19,7 +19,10 @@ import { } from "./common/fetchCdtnAdminDocuments"; import { splitArticle } from "./fichesTravailSplitter"; import { getVersions } from "./versions"; -import { generateContributions } from "./contributions"; +import { + fetchContributionDocumentToPublish, + generateContributions, +} from "./contributions"; import { generateAgreements } from "./agreements"; import { fetchThemes } from "./themes/fetchThemes"; import { updateExportEsStatusWithDocumentsCount } from "./exportStatus/updateExportEsStatusWithDocumentsCount"; @@ -27,6 +30,7 @@ import { generatePrequalified } from "./prequalified"; import { generateEditorialContents } from "./informations/generate"; import { populateRelatedDocuments } from "./common/populateRelatedDocuments"; import { mergeRelatedDocumentsToEditorialContents } from "./informations/mergeRelatedDocumentsToEditorialContents"; +import { updateExportStatuses } from "./documents/updateExportStatuses"; import { getGlossary } from "./common/fetchGlossary"; /** @@ -54,7 +58,8 @@ export async function getDuplicateSlugs(allDocuments: any) { } export async function cdtnDocumentsGen( - updateDocs: (source: string, documents: unknown[]) => Promise + updateDocs: (source: string, documents: unknown[]) => Promise, + isProd: boolean ) { let documentsCount: Partial = {}; @@ -62,6 +67,8 @@ export async function cdtnDocumentsGen( const getBreadcrumbs = buildGetBreadcrumbs(themes); + const contributionsToPublish = await fetchContributionDocumentToPublish(); + logger.info("=== Courriers ==="); const modelesDeCourriers = await getDocumentBySource( SOURCES.LETTERS, @@ -328,6 +335,10 @@ export async function cdtnDocumentsGen( }, ]); + if (isProd && contributionsToPublish) { + await updateExportStatuses(contributionsToPublish); + } + logger.info("=== Save the documents length ==="); documentsCount = { ...documentsCount, diff --git a/targets/export-elasticsearch/src/ingester/contributions/__tests__/filterContributionToPublish.test.ts b/targets/export-elasticsearch/src/ingester/contributions/__tests__/filterContributionToPublish.test.ts new file mode 100644 index 000000000..a4a511d44 --- /dev/null +++ b/targets/export-elasticsearch/src/ingester/contributions/__tests__/filterContributionToPublish.test.ts @@ -0,0 +1,112 @@ +import { + ContributionDocumentJson, + ContributionsAnswers, + DocumentElasticWithSource, +} from "@socialgouv/cdtn-types"; +import { filterContributionDocumentsToPublish } from "../fetchContributionDocumentsToPublish"; + +const contributionMock: ContributionsAnswers = { + id: "d61a3e21-9bf1-4199-b9d7-944c2382750c", + updatedAt: "2024-03-25T17:25:33.002376+00:00", + agreement: { + id: "id", + kali_id: "", + name: "", + }, + cdtn_references: [], + content: "", + content_fiche_sp: { + initial_id: "", + document: { + date: "", + description: "", + raw: "", + referencedTexts: [], + url: "", + }, + }, + content_type: "ANSWER", + description: "", + kali_references: [], + legi_references: [], + message_block_generic_no_CDT: "", + other_references: [], + question: { + content: "", + id: "", + order: 1, + }, + statuses: [], +}; + +const doc: DocumentElasticWithSource = { + id: "", + title: "", + excludeFromSearch: true, + slug: "", + source: "contributions", + text: "", + isPublished: true, + metaDescription: "", + references: [], + linkedContent: [], + questionIndex: 1, + questionName: "", + questionId: "", + genericAnswerId: "", + type: "cdt", + idcc: "", + refs: [], + breadcrumbs: [], + cdtnId: "", + contentType: "ANSWER", + description: "", + contribution: contributionMock, +}; + +describe("filterContributionDocumentsToPublish", () => { + it("should send the list of contributions which have been updated after last export", () => { + const result = filterContributionDocumentsToPublish([ + { + ...doc, + cdtnId: "388f8d7860", + export: { + id: "id", + createdAt: "2024-06-03T08:10:03.697249+00:00", + }, + contribution: { + ...contributionMock, + statuses: [ + { + status: "TO_PUBLISH", + createdAt: "2024-03-27T14:26:28.387898+00:00", + }, + ], + }, + }, + ]); + expect(result?.length).toBe(0); + }); + it("should send the list of contributions which have been updated after last export2", () => { + const result = filterContributionDocumentsToPublish([ + { + ...doc, + cdtnId: "388f8d7860", + export: { + id: "id", + createdAt: "2024-06-03T08:10:03.697249+00:00", + }, + contribution: { + ...contributionMock, + statuses: [ + { + status: "TO_PUBLISH", + createdAt: "2024-06-27T14:26:28.387898+00:00", + }, + ], + }, + }, + ]); + expect(result?.length).toBe(1); + }); +}); diff --git a/targets/export-elasticsearch/src/ingester/contributions/fetchContributionDocumentsToPublish.ts b/targets/export-elasticsearch/src/ingester/contributions/fetchContributionDocumentsToPublish.ts new file mode 100644 index 000000000..72ec77bda --- /dev/null +++ b/targets/export-elasticsearch/src/ingester/contributions/fetchContributionDocumentsToPublish.ts @@ -0,0 +1,64 @@ +import { + ContributionDocumentJson, + DocumentElasticWithSource, +} from "@socialgouv/cdtn-types"; +import { context } from "../context"; +import { gqlClient } from "@shared/utils"; + +export const fetchContributionDocumentsQuery = ` +query fetchContributions { + documents(where: {source: {_eq: "contributions"}}) { + cdtnId: cdtn_id + export { + createdAt: created_at + } + contribution { + id + updatedAt: updated_at + statuses(where:{status: {_eq: "TO_PUBLISH"}}, order_by: {created_at: desc}, limit: 1) { + status + createdAt: created_at + } + } + } + } + `; + +interface HasuraReturn { + documents: [DocumentElasticWithSource] | undefined; +} + +export function filterContributionDocumentsToPublish( + contributionDocs: + | DocumentElasticWithSource[] + | undefined +): DocumentElasticWithSource[] | undefined { + return contributionDocs?.filter((doc) => { + const exportDate = doc.export?.createdAt + ? new Date(doc.export.createdAt).getTime() + : 0; + const statusDate = doc.contribution?.statuses?.length + ? new Date(doc.contribution.statuses[0].createdAt).getTime() + : 0; + return statusDate > exportDate; + }); +} + +export async function fetchContributionDocumentToPublish(): Promise< + DocumentElasticWithSource[] | undefined +> { + const HASURA_GRAPHQL_ENDPOINT = + context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql"; + const HASURA_GRAPHQL_ENDPOINT_SECRET = + context.get("cdtnAdminEndpointSecret") || "admin1"; + const res = await gqlClient({ + graphqlEndpoint: HASURA_GRAPHQL_ENDPOINT, + adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET, + }) + .query(fetchContributionDocumentsQuery, {}) + .toPromise(); + if (res.error) { + throw res.error; + } + return filterContributionDocumentsToPublish(res.data?.documents); +} diff --git a/targets/export-elasticsearch/src/ingester/contributions/index.ts b/targets/export-elasticsearch/src/ingester/contributions/index.ts index e722cf183..d41d94130 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/index.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/index.ts @@ -1,2 +1,3 @@ export * from "./helpers"; export * from "./generate"; +export * from "./fetchContributionDocumentsToPublish"; \ No newline at end of file diff --git a/targets/export-elasticsearch/src/ingester/documents/fetchLastExportStatus.ts b/targets/export-elasticsearch/src/ingester/documents/fetchLastExportStatus.ts new file mode 100644 index 000000000..813acb8fb --- /dev/null +++ b/targets/export-elasticsearch/src/ingester/documents/fetchLastExportStatus.ts @@ -0,0 +1,33 @@ +import { Export } from "@socialgouv/cdtn-types"; +import { context } from "../context"; +import { gqlClient } from "@shared/utils"; + +export const fetchLastExportStatusQuery = ` + query lastExportStatus { + exportEsStatus: export_es_status(order_by: {created_at: desc}, limit: 1) { + id + } + } + `; + +interface HasuraReturn { + exportEsStatus: [Export] | undefined +} + + +export async function fetchLastExportStatus(): Promise { + const HASURA_GRAPHQL_ENDPOINT = + context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql"; + const HASURA_GRAPHQL_ENDPOINT_SECRET = + context.get("cdtnAdminEndpointSecret") || "admin1"; + const res = await gqlClient({ + graphqlEndpoint: HASURA_GRAPHQL_ENDPOINT, + adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET, + }) + .query(fetchLastExportStatusQuery, {}) + .toPromise(); + if (res.error) { + throw res.error; + } + return res.data?.exportEsStatus?.[0]; +} diff --git a/targets/export-elasticsearch/src/ingester/documents/updateExportStatuses.ts b/targets/export-elasticsearch/src/ingester/documents/updateExportStatuses.ts new file mode 100644 index 000000000..89312c20e --- /dev/null +++ b/targets/export-elasticsearch/src/ingester/documents/updateExportStatuses.ts @@ -0,0 +1,50 @@ +import { fetchLastExportStatus } from "./fetchLastExportStatus"; +import { gqlClient } from "@shared/utils"; +import { context } from "../context"; +import { + ContributionDocumentJson, + DocumentElasticWithSource, +} from "@socialgouv/cdtn-types"; + +export const updateToLastExportStatusMutation = `mutation updateToLastExportStatus($cdtnIds: [String!], $exportId: uuid) { + updateDocuments: update_documents( + where: {cdtn_id: {_in: $cdtnIds}}, + _set: { + exportId: $exportId + } + ) { + returning { + cdtn_id + } + } +}`; + +export async function updateExportStatuses( + contributionsToPublish: DocumentElasticWithSource[] +) { + const HASURA_GRAPHQL_ENDPOINT = + context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql"; + const HASURA_GRAPHQL_ENDPOINT_SECRET = + context.get("cdtnAdminEndpointSecret") || "admin1"; + const exportStatus = await fetchLastExportStatus(); + + if (!exportStatus?.id) { + return; + } + const cdtnIds = contributionsToPublish.map( + (contribution) => contribution.cdtnId + ); + const { id: exportId } = exportStatus; + + if (cdtnIds.length) { + const res = await gqlClient({ + graphqlEndpoint: HASURA_GRAPHQL_ENDPOINT, + adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET, + }) + .mutation(updateToLastExportStatusMutation, { cdtnIds, exportId }) + .toPromise(); + if (res.error) { + throw res.error; + } + } +} diff --git a/targets/export-elasticsearch/src/ingester/ingest.ts b/targets/export-elasticsearch/src/ingester/ingest.ts index 827687845..d48fd6bd0 100644 --- a/targets/export-elasticsearch/src/ingester/ingest.ts +++ b/targets/export-elasticsearch/src/ingester/ingest.ts @@ -60,7 +60,8 @@ export async function ingest( nlpUrl: string | undefined, suggestIndexName: string | undefined, bufferSize: number | undefined, - suggestFile: string | undefined + suggestFile: string | undefined, + isProd = false ) { context.provide(); process.env.NLP_URL = nlpUrl; //pour setter la variable d'environment du package elasticsearch... @@ -73,7 +74,8 @@ export async function ingest( nlpUrl, suggestIndexName, bufferSize, - suggestFile + suggestFile, + isProd ); } @@ -86,7 +88,8 @@ async function runIngester( nlpUrl: string | undefined, suggestIndexName: string | undefined, bufferSize: number | undefined, - suggestFile: string | undefined + suggestFile: string | undefined, + isProd: boolean ) { const ES_INDEX_PREFIX = esIndexPrefix ?? "cdtn"; @@ -155,7 +158,7 @@ async function runIngester( size: 800, }); }; - await cdtnDocumentsGen(updateDocs); + await cdtnDocumentsGen(updateDocs, isProd); logger.info(`done in ${(Date.now() - t0) / 1000} s`); diff --git a/targets/export-elasticsearch/src/workers/ingester-prod.ts b/targets/export-elasticsearch/src/workers/ingester-prod.ts index f6649d343..e4624b88f 100644 --- a/targets/export-elasticsearch/src/workers/ingester-prod.ts +++ b/targets/export-elasticsearch/src/workers/ingester-prod.ts @@ -15,7 +15,8 @@ const ingester = async (): Promise => { process.env.NLP_URL, undefined, undefined, - undefined + undefined, + true ); resolve("Export elasticsearch completed successfully"); } catch (error: unknown) { diff --git a/targets/frontend/src/components/contributions/answers/Answer.tsx b/targets/frontend/src/components/contributions/answers/Answer.tsx index e9f7e5ebd..50e3d5eb8 100644 --- a/targets/frontend/src/components/contributions/answers/Answer.tsx +++ b/targets/frontend/src/components/contributions/answers/Answer.tsx @@ -16,13 +16,13 @@ import { Answer, Status } from "../type"; import { useContributionAnswerUpdateMutation } from "./answer.mutation"; import { useContributionAnswerQuery } from "./answer.query"; import { Comments } from "./Comments"; -import { statusesMapping } from "../status/data"; import { SnackBar } from "../../utils/SnackBar"; import { Breadcrumb, BreadcrumbLink } from "src/components/utils"; import { AnswerForm } from "./AnswerForm"; import { fr } from "@codegouvfr/react-dsfr"; import { usePublishContributionMutation } from "./usePublishAnswer"; import { useGenericContributionAnswerQuery } from "./answerGeneric.query"; +import { StatusPublicationContainer } from "../status/StatusPublication"; export type ContributionsAnswerProps = { id: string; @@ -71,7 +71,7 @@ export const ContributionsAnswer = ({ cdtnReferences: data.cdtnReferences, otherReferences: data.otherReferences, }); - if (newStatus === "PUBLISHED") { + if (newStatus === "TO_PUBLISH") { await onPublish(answer.id); } setSnack({ @@ -80,8 +80,8 @@ export const ContributionsAnswer = ({ message: "La réponse a été modifiée", }); } catch (e: any) { - // Dans le cas où il y a une erreur au niveau de la publication (PUBLISHED), on revert le status en VALIDATED - if (newStatus === "PUBLISHED" && answer && user) { + // Dans le cas où il y a une erreur au niveau de la publication (TO_PUBLISH), on revert le status en VALIDATED + if (newStatus === "TO_PUBLISH" && answer && user) { await updateAnswer({ content: data.content, id: answer.id, @@ -127,9 +127,19 @@ export const ContributionsAnswer = ({ {answer?.status && ( -
- -
+ + + + )} diff --git a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx index bcab68eef..03fb17684 100644 --- a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx +++ b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx @@ -214,6 +214,7 @@ export const AnswerForm = ({ value: "GENERIC_NO_CDT", }, ]; + const primaryButtonLabel = getPrimaryButtonLabel(status); return (
@@ -331,15 +332,17 @@ export const AnswerForm = ({ > Sauvegarder - + {primaryButtonLabel && ( + + )} )} diff --git a/targets/frontend/src/components/contributions/answers/Comment.tsx b/targets/frontend/src/components/contributions/answers/Comment.tsx index f1c6e1a2f..c28ae86d5 100644 --- a/targets/frontend/src/components/contributions/answers/Comment.tsx +++ b/targets/frontend/src/components/contributions/answers/Comment.tsx @@ -33,6 +33,7 @@ export const Comment = ({ comment, onDelete }: Props) => { sx={{ border: "1px solid", borderColor: "grey.300", + minWidth: "300px", }} mt={1} mb={1} diff --git a/targets/frontend/src/components/contributions/answers/__tests__/AnswerForm.test.tsx b/targets/frontend/src/components/contributions/answers/__tests__/AnswerForm.test.tsx index 875203d83..30ede089c 100644 --- a/targets/frontend/src/components/contributions/answers/__tests__/AnswerForm.test.tsx +++ b/targets/frontend/src/components/contributions/answers/__tests__/AnswerForm.test.tsx @@ -142,6 +142,11 @@ const answerBase: AnswerWithStatus = { }, }, updateDate: "29/09/2023", + publication: { + export: { + createdAt: "29/09/2023", + }, + }, }; const onSubmit = jest.fn(() => Promise.resolve()); diff --git a/targets/frontend/src/components/contributions/answers/answer.query.ts b/targets/frontend/src/components/contributions/answers/answer.query.ts index 204f81beb..c3adf3664 100644 --- a/targets/frontend/src/components/contributions/answers/answer.query.ts +++ b/targets/frontend/src/components/contributions/answers/answer.query.ts @@ -43,6 +43,11 @@ query contribution_answer($id: uuid) { name } } + publication { + export { + createdAt: created_at + } + } kaliReferences: kali_references { label kaliArticle: kali_article { diff --git a/targets/frontend/src/components/contributions/publication/index.ts b/targets/frontend/src/components/contributions/publication/index.ts new file mode 100644 index 000000000..f9a34683f --- /dev/null +++ b/targets/frontend/src/components/contributions/publication/index.ts @@ -0,0 +1 @@ +export * from "./isPublished"; diff --git a/targets/frontend/src/components/contributions/publication/isPublished.ts b/targets/frontend/src/components/contributions/publication/isPublished.ts new file mode 100644 index 000000000..fd083d29d --- /dev/null +++ b/targets/frontend/src/components/contributions/publication/isPublished.ts @@ -0,0 +1,9 @@ +export const isPublished = ({ + statusDate, + exportDate, +}: { + statusDate: string; + exportDate: string; +}): boolean => { + return new Date(exportDate).getTime() > new Date(statusDate).getTime(); +}; diff --git a/targets/frontend/src/components/contributions/questionList/QuestionList.query.ts b/targets/frontend/src/components/contributions/questionList/QuestionList.query.ts index ca0d7d5ec..9badc25f5 100644 --- a/targets/frontend/src/components/contributions/questionList/QuestionList.query.ts +++ b/targets/frontend/src/components/contributions/questionList/QuestionList.query.ts @@ -10,21 +10,24 @@ export const questionListQuery = `query questions_answers($search: String) { }, order_by: {order: asc} ) { - id, - content, - order, - answers { - statuses(order_by: {created_at: desc}, limit: 1) { - status - user { - name - } + id + content + order + answers_aggregate(where: {cdtnId: {_is_null: false }}) { + aggregate { + count } } } }`; export type QueryQuestionAnswer = Answer; -export type QueryQuestion = Question; +export type QueryQuestion = Question & { + answers_aggregate: { + aggregate: { + count: number; + } + } +}; export type QueryResult = { contribution_questions: QueryQuestion[]; @@ -61,6 +64,6 @@ export const useQuestionListQuery = ({ }, }); return { - rows: formatAnswers(result.data?.contribution_questions), + rows: result.data?.contribution_questions ?? [], }; }; diff --git a/targets/frontend/src/components/contributions/questionList/QuestionList.tsx b/targets/frontend/src/components/contributions/questionList/QuestionList.tsx index 2021c02c6..de3aa741f 100644 --- a/targets/frontend/src/components/contributions/questionList/QuestionList.tsx +++ b/targets/frontend/src/components/contributions/questionList/QuestionList.tsx @@ -1,6 +1,4 @@ import { - Card, - CardContent, Paper, Stack, Table, @@ -11,7 +9,6 @@ import { TableRow, TextField, Tooltip, - Typography, } from "@mui/material"; import { useState } from "react"; @@ -20,10 +17,7 @@ import { useQuestionListQuery, } from "./QuestionList.query"; import { QuestionRow } from "./QuestionRow"; -import { fr } from "@codegouvfr/react-dsfr"; import { statusesMapping } from "../status/data"; -import { StatusStats } from "../status/StatusStats"; -import { Answer } from "../type"; export const countAnswersWithStatus = ( answers: QueryQuestionAnswer[] | undefined, @@ -41,10 +35,6 @@ export const QuestionList = (): JSX.Element => { search, }); - const aggregatedRow = rows.flatMap(({ answers }) => - answers?.length ? (answers as Answer[]) : [] - ); - const total = aggregatedRow.length; return ( { }} data-testid="contributions-list-search" /> - - - Total - - {total} - - - - - ({ - status, - count: countAnswersWithStatus(aggregatedRow, status), - }))} - total={total} - > @@ -91,15 +60,7 @@ export const QuestionList = (): JSX.Element => { Questions ({rows.length}) - {Object.entries(statusesMapping).map( - ([_, { text, icon, color }]) => { - return ( - - {icon} - - ); - } - )} + Publiées diff --git a/targets/frontend/src/components/contributions/questionList/QuestionRow.tsx b/targets/frontend/src/components/contributions/questionList/QuestionRow.tsx index 9abc25d57..52ec6c720 100644 --- a/targets/frontend/src/components/contributions/questionList/QuestionRow.tsx +++ b/targets/frontend/src/components/contributions/questionList/QuestionRow.tsx @@ -2,9 +2,7 @@ import TableCell from "@mui/material/TableCell"; import TableRow from "@mui/material/TableRow"; import { useRouter } from "next/router"; -import { StatusRecap } from "../status"; import { QueryQuestion } from "./QuestionList.query"; -import { Answer } from "../type"; export const QuestionRow = (props: { row: QueryQuestion }) => { const { row } = props; @@ -23,10 +21,9 @@ export const QuestionRow = (props: { row: QueryQuestion }) => { {row.order} - {row.content} - + + {row.answers_aggregate.aggregate.count || "-"} + ); }; diff --git a/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts b/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts index 28c64d7b5..517d75f87 100644 --- a/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts +++ b/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts @@ -19,16 +19,24 @@ const createAnswerStatus = (status: Status): AnswerStatus => { export const mock: QuestionListQueryResult = { rows: [ { - answers: [createAnswerStatus("TODO"), createAnswerStatus("REDACTING")], content: "question1", id: "questionId1", order: 1, + answers_aggregate: { + aggregate: { + count: 50 + } + } }, { - answers: [createAnswerStatus("TODO"), createAnswerStatus("TODO")], content: "question2", id: "questionId2", order: 2, + answers_aggregate: { + aggregate: { + count: 50 + } + } }, ], }; diff --git a/targets/frontend/src/components/contributions/questions/EditQuestion.tsx b/targets/frontend/src/components/contributions/questions/EditQuestion.tsx index c596f13cc..c8bc9c323 100644 --- a/targets/frontend/src/components/contributions/questions/EditQuestion.tsx +++ b/targets/frontend/src/components/contributions/questions/EditQuestion.tsx @@ -7,10 +7,7 @@ import { QuestionAnswerList } from "./EditQuestionAnswerList"; import { EditQuestionForm } from "./EditQuestionForm"; import { useQuestionQuery } from "./Question.query"; import { Breadcrumb, BreadcrumbLink } from "src/components/utils"; -import { statusesMapping } from "../status/data"; -import { countAnswersWithStatus } from "../questionList"; import { Answer } from "../type"; -import { StatusStats } from "../status/StatusStats"; import { usePublishContributionMutation } from "../answers/usePublishAnswer"; import { useSession } from "next-auth/react"; import { useContributionAnswerUpdateStatusMutation } from "../answers/answerStatus.mutation"; @@ -68,11 +65,7 @@ export const EditQuestion = ({ ); } - const Header = ({ answers }: { answers: Answer[] }) => { - const statusCounts = Object.keys(statusesMapping).map((status) => { - const count = countAnswersWithStatus(answers, status); - return { status, count }; - }); + const Header = () => { return ( <> @@ -81,12 +74,6 @@ export const EditQuestion = ({ {`${data?.question?.order} - ${data?.question?.content}`} - - - ); }; @@ -122,7 +109,7 @@ export const EditQuestion = ({ await onPublish(id); await updateAnswerStatus({ id: id, - status: "PUBLISHED", + status: "TO_PUBLISH", userId: user?.id, }); data.reExecute(); @@ -135,7 +122,7 @@ export const EditQuestion = ({ justifyContent="start" spacing={2} > -
+
diff --git a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx index 7761df139..a313e6a44 100644 --- a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx +++ b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx @@ -19,6 +19,7 @@ import { Answer } from "../type"; import { StatusContainer } from "../status"; import { useRouter } from "next/router"; import { fr } from "@codegouvfr/react-dsfr"; +import { StatusPublicationContainer } from "../status/StatusPublication"; type EditQuestionAnswerListProps = { answers: Answer[]; @@ -136,6 +137,7 @@ export const QuestionAnswerList = ({ Convention Collective Type Statut + Publication @@ -195,9 +197,25 @@ export const QuestionAnswerList = ({ onClick={() => redirectToAnswer(answer.id)} > {answer.status && ( - + )} + redirectToAnswer(answer.id)} + > + + ); })} diff --git a/targets/frontend/src/components/contributions/questions/Question.query.ts b/targets/frontend/src/components/contributions/questions/Question.query.ts index 8b6f989f9..35ef5a712 100644 --- a/targets/frontend/src/components/contributions/questions/Question.query.ts +++ b/targets/frontend/src/components/contributions/questions/Question.query.ts @@ -27,10 +27,16 @@ query SelectQuestion($questionId: uuid) { } statuses(order_by: {created_at: desc}, limit: 1) { status + createdAt: created_at user { name } } + publication { + export { + createdAt: created_at + } + } } } contribution_question_messages { diff --git a/targets/frontend/src/components/contributions/status/Status.tsx b/targets/frontend/src/components/contributions/status/Status.tsx index 43cac7794..d96149d1e 100644 --- a/targets/frontend/src/components/contributions/status/Status.tsx +++ b/targets/frontend/src/components/contributions/status/Status.tsx @@ -1,29 +1,46 @@ import { Box, Stack, Tooltip } from "@mui/material"; -import { AnswerStatus } from "../type"; +import { Status } from "../type"; import { statusesMapping } from "./data"; +import { isPublished } from "../publication"; export const StatusContainer = ({ status, + statusDate, + exportDate, + displayText = false, dataTestid, + center = false, }: { - status: AnswerStatus; + status: Status; + statusDate?: string; + exportDate?: string | null; + displayText?: boolean; dataTestid?: string; + center?: boolean; }) => { + if (status === "TO_PUBLISH") { + if (statusDate && exportDate && isPublished({ statusDate, exportDate })) { + status = "TO_PUBLISH"; + } else { + status = "PUBLISHING"; + } + } + const tooltipTitle = statusesMapping[status].text; return ( - + - {statusesMapping[status.status].icon} - {statusesMapping[status.status].text} + {statusesMapping[status].icon} + {displayText && {tooltipTitle}} ); diff --git a/targets/frontend/src/components/contributions/status/StatusPublication.tsx b/targets/frontend/src/components/contributions/status/StatusPublication.tsx new file mode 100644 index 000000000..84770888a --- /dev/null +++ b/targets/frontend/src/components/contributions/status/StatusPublication.tsx @@ -0,0 +1,48 @@ +import { format, parseISO } from "date-fns"; +import { Box, Stack, Tooltip } from "@mui/material"; + +import { Status } from "../type"; +import { statusesMapping } from "./data"; + +export const StatusPublicationContainer = ({ + status, + exportDate, + displayText = false, + dataTestid, + center = false, +}: { + status: Status; + exportDate?: string | null; + displayText?: boolean; + dataTestid?: string; + center?: boolean; +}) => { + let tooltipText: string | undefined; + if (!exportDate) { + status = "NOT_PUBLISHED"; + tooltipText = statusesMapping[status].text; + } else { + status = "PUBLISHED"; + tooltipText = `${statusesMapping[status].text} le ${format( + parseISO(exportDate), + "dd/MM/yyyy HH:mm:ss" + )}`; + } + return ( + + + {statusesMapping[status].icon} + {displayText && {tooltipText}} + + + ); +}; diff --git a/targets/frontend/src/components/contributions/status/StatusRecap.tsx b/targets/frontend/src/components/contributions/status/StatusRecap.tsx index c030e6137..7a44b152a 100644 --- a/targets/frontend/src/components/contributions/status/StatusRecap.tsx +++ b/targets/frontend/src/components/contributions/status/StatusRecap.tsx @@ -11,20 +11,22 @@ export const StatusRecap = ({ }) => { return ( <> - {Object.entries(statusesMapping).map(([status, { color }]) => { - const count = countAnswersWithStatus(answers, status); - return ( - - {count ? count : "-"} - - ); - })} + {Object.entries(statusesMapping) + .filter(([status]) => status === "TO_PUBLISH") + .map(([status, { color }]) => { + const count = countAnswersWithStatus(answers, status); + return ( + + {count ? count : "-"} + + ); + })} ); }; diff --git a/targets/frontend/src/components/contributions/status/data.tsx b/targets/frontend/src/components/contributions/status/data.tsx index c32baf64d..7db07ae8e 100644 --- a/targets/frontend/src/components/contributions/status/data.tsx +++ b/targets/frontend/src/components/contributions/status/data.tsx @@ -2,8 +2,10 @@ import CheckIcon from "@mui/icons-material/Check"; import ClearIcon from "@mui/icons-material/Clear"; import DescriptionIcon from "@mui/icons-material/Description"; import EditNoteIcon from "@mui/icons-material/EditNote"; -import TaskAltIcon from "@mui/icons-material/TaskAlt"; import VisibilityIcon from "@mui/icons-material/Visibility"; +import CloudDoneIcon from "@mui/icons-material/CloudDone"; +import CloudOffIcon from "@mui/icons-material/CloudOff"; +import TaskAltIcon from "@mui/icons-material/TaskAlt"; import { fr } from "@codegouvfr/react-dsfr"; export type StatusesMapping = { @@ -43,10 +45,24 @@ export const statusesMapping: StatusesMapping = { icon: , text: "Validé", }, - - PUBLISHED: { + TO_PUBLISH: { color: fr.colors.decisions.text.default.success.default, icon: , text: "Publié", }, + PUBLISHING: { + color: fr.colors.decisions.text.default.warning.default, + icon: , + text: "À publier", + }, + PUBLISHED: { + color: fr.colors.decisions.text.default.success.default, + icon: , + text: "Publié", + }, + NOT_PUBLISHED: { + color: fr.colors.decisions.text.default.error.default, + icon: , + text: "Non Publié", + }, }; diff --git a/targets/frontend/src/components/contributions/status/utils.ts b/targets/frontend/src/components/contributions/status/utils.ts index b64c28d9f..277580814 100644 --- a/targets/frontend/src/components/contributions/status/utils.ts +++ b/targets/frontend/src/components/contributions/status/utils.ts @@ -16,7 +16,7 @@ export const getNextStatus = (status: Status): Status => { case "VALIDATING": return "VALIDATED"; case "VALIDATED": - return "PUBLISHED"; + return "TO_PUBLISH"; case "TODO": case "REDACTING": default: @@ -31,9 +31,9 @@ export const getPrimaryButtonLabel = (status: Status): string => { case "VALIDATING": return "Valider"; case "VALIDATED": - return "Publier"; - case "PUBLISHED": - return "Publiée"; + return "À publier"; + case "TO_PUBLISH": + return ""; case "TODO": case "REDACTING": default: diff --git a/targets/frontend/src/components/contributions/type.ts b/targets/frontend/src/components/contributions/type.ts index 430e602e6..4b3d6bd9c 100644 --- a/targets/frontend/src/components/contributions/type.ts +++ b/targets/frontend/src/components/contributions/type.ts @@ -22,7 +22,10 @@ export const statusSchema = z.enum([ "REDACTED", "VALIDATING", "VALIDATED", + "TO_PUBLISH", + "PUBLISHING", "PUBLISHED", + "NOT_PUBLISHED", ]); export type Status = z.infer; @@ -164,6 +167,11 @@ export const commentsSchema = z.object({ }); export type Comments = z.infer; +export const exportStatus = z.object({ + createdAt: z.string(), +}); +export type ExportStatus = z.infer; + export const answerRelationSchema = answerBaseSchema.extend({ agreement: agreementSchema, statuses: z.array(answerStatusSchema), @@ -175,6 +183,9 @@ export const answerRelationSchema = answerBaseSchema.extend({ contentFichesSpDocument: documentSchema.nullable().optional(), question: questionBaseSchema, answerComments: z.array(commentsSchema), + publication: z.object({ + export: exportStatus, + }), }); export type Answer = z.infer; diff --git a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts index cc5747e49..8fb789087 100644 --- a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts +++ b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts @@ -31,6 +31,7 @@ describe("mapContributionToDocument", () => { it("devrait mapper l'answer d'un document sans fiche SP", async () => { const inputContribution: ContributionsAnswers = { + updatedAt: "", id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: "

Quand une femme tombe enceinte et décide de partir en congé maternité, cette dernière a droit à des indemnités journalières de sécurité sociale venant indemniser la période durant laquelle elle ne peut plus travailler. Certaines conventions collectives prévoient également un maintien de salaire versé par l’employeur. Si le maintien est à 100%, dans ce cas, les deux mécanismes ne sont pas cumulables. Si le maintien est inférieur à 100%, le pourcentage de rémunération restant est indemnisé par les indemnités de Sécurité sociale. 

Maintien de salaire

Les salariées ayant au moins une année de présence continue dans l'entreprise à la date de l'accouchement ont droit à un maintien de salaire, après déduction des indemnités de Sécurité sociale, qui leur assure leur salaire habituel, et ce pendant une durée de 36 jours (en principe 18 jours avant l’accouchement, 18 jours après).

Pour les salariées cadres âgées de moins de 25 ans et les autres salariées âgées de moins de 22 ans à la date de l'accouchement, la période de 36 jours est augmentée de 2 jours par enfant à charge. L'indemnité complémentaire ne pourra pas être versée plus de 46 jours. Est considéré comme enfant à charge tout enfant à charge de la salariée au sens de la législation des prestations familiales et âgé de moins de 15 ans à la date de l'accouchement.

A noter : Les périodes de suspension du contrat de travail (maladie, etc.) sont prises en compte pour l'ancienneté.

Si la salariée ne respecte pas la condition d’ancienneté, elle n’a pas droit au maintien de salaire versé par l’employeur mais aura potentiellement droit aux indemnités journalières de Sécurité sociale si elle respecte ses conditions d’octroi. 

Indemnités de Sécurité sociale

Conditions d’ouverture des droits aux indemnités journalières de Sécurité sociale

Pour être indemnisée, la salariée doit remplir les conditions suivantes :

  • Etre affiliée à la Sécurité sociale depuis au moins 10 mois à la date présumée de l'accouchement ;

  • cesser son activité professionnelle pendant au moins 8 semaines ;

  • avoir : 

    • soit travaillé au moins 150 heures au cours des 3 mois civils ou des 90 jours précédant l'arrêt, 

    • soit travaillé au moins 600 heures au cours des 12 mois précédant l’arrêt de travail, 

    • soit cotisé, au cours des 6 mois civils précédant l'arrêt, sur la base d'une rémunération au moins égale à 1 015 fois le montant du Smic horaire fixé au début de cette période, 

    • soit cotisé au cours des 12 mois civils précédant l’arrêt, sur la base d'une rémunération au moins égale à 2030 fois le montant du Smic horaire fixé en début de période.

Exemple : le congé a débuté le 1er juillet 2023 pour une date présumée d'accouchement au 1er septembre 2023.

Le droit aux indemnités journalières est ouvert si :

  • La salariée était déjà affiliée à la Sécurité sociale avant novembre 2022 ;

  • et a travaillé soit au moins 150 heures entre le 1er avril 2023 et le 30 juin 2023, soit au moins 600 heures entre le 1er juillet 2022 et le 30 juin 2023, soit a cotisé entre le 1er janvier 2023 et le 30 juin 2023 sur la base d'une rémunération au moins égale à 11 439,05 €, soit a cotisé entre le 1er juillet 2022 et le 30 juin 2023 sur la base d’une rémunération au moins égale à 22 878,1 €.

Montant

La CPAM verse des indemnités journalières, dont le montant est fixé selon les étapes de calcul suivantes :

  • Calcul du salaire journalier de base : somme des 3 derniers salaires bruts perçus avant la date d'interruption du travail, divisé par 91,25.

  • Montant maximal du salaire journalier de base : le salaire pris en compte ne peut pas dépasser le plafond mensuel de la sécurité sociale en vigueur lors du dernier jour du mois qui précède l'arrêt (soit 3 666 € par mois en 2023, ou 3 428 € en 2022).

  • Taux forfaitaire appliqué par la CPAM : la CPAM retire à ce salaire journalier de base un taux forfaitaire de 21 %.

  • Montant minimal et montant maximal des indemnités journalières : le montant ne peut pas être inférieur à 10,24 € ni supérieur à 95,22 € par jour.

Versement

Les indemnités journalières sont versées tous les 14 jours.

", @@ -235,6 +236,7 @@ describe("mapContributionToDocument", () => { it("devrait retourner undefined si de type UNKNOWN", async () => { const inputContribution: ContributionsAnswers = { + updatedAt: "", id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: null, description: null, @@ -269,6 +271,7 @@ describe("mapContributionToDocument", () => { describe("avec une contrib generic de type GENERIC_NO_CDT", () => { it("devrait mapper l'answer de la contrib generic", async () => { const inputContribution: ContributionsAnswers = { + updatedAt: "", id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: null, description: null, @@ -323,6 +326,7 @@ describe("mapContributionToDocument", () => { "devrait throw une erreur si une contrib personnalisé est de type $type", async ({ type }) => { const inputContribution: ContributionsAnswers = { + updatedAt: "", id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: null, description: null, @@ -364,6 +368,7 @@ describe("mapContributionToDocument", () => { describe("flag is_searchable", () => { it("devrait être à false pour une réponse personnalisée", async () => { + // @ts-ignore const inputContribution: ContributionsAnswers = { id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: "

Texte de la réponse

", @@ -414,6 +419,7 @@ describe("mapContributionToDocument", () => { }); it("devrait être à true pour une réponse générique", async () => { + // @ts-ignore const inputContribution: ContributionsAnswers = { id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: "

Texte de la réponse

", @@ -447,6 +453,7 @@ describe("mapContributionToDocument", () => { }); it("devrait garder la même valeur du document pour une réponse générique", async () => { + // @ts-ignore const inputContribution: ContributionsAnswers = { id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: "

Texte de la réponse

", @@ -497,6 +504,7 @@ describe("mapContributionToDocument", () => { }); it("2 contribs de la même question doivent générer des cdtn_id différent si elle n'existe pas", async () => { + // @ts-ignore const inputContribution: ContributionsAnswers = { id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", content: "

Texte de la réponse

", @@ -528,6 +536,7 @@ describe("mapContributionToDocument", () => { ); expect(result!.cdtn_id).toEqual("b3bc78aed5"); + // @ts-ignore const inputContribution2: ContributionsAnswers = { id: "effee3b9-84fb-4667-944b-4b1e1fd14eb6", content: "

Texte de la réponse

", diff --git a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml index 96d7b71a9..f482cdd8b 100644 --- a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml +++ b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml @@ -1,6 +1,13 @@ table: name: answers schema: contribution +configuration: + column_config: + cdtn_id: + custom_name: cdtnId + custom_column_names: + cdtn_id: cdtnId + custom_root_fields: {} object_relationships: - name: agreement using: @@ -8,6 +15,15 @@ object_relationships: - name: document using: foreign_key_constraint_on: content_service_public_cdtn_id + - name: publication + using: + manual_configuration: + column_mapping: + cdtn_id: cdtn_id + insertion_order: null + remote_table: + name: documents + schema: public - name: question using: foreign_key_constraint_on: question_id @@ -61,6 +77,7 @@ select_permissions: permission: columns: - agreement_id + - cdtn_id - content - content_service_public_cdtn_id - content_type @@ -75,6 +92,7 @@ update_permissions: - role: super permission: columns: + - cdtn_id - content - content_service_public_cdtn_id - content_type diff --git a/targets/hasura/metadata/databases/default/tables/public_documents.yaml b/targets/hasura/metadata/databases/default/tables/public_documents.yaml index 37aa641fa..dbab000b6 100644 --- a/targets/hasura/metadata/databases/default/tables/public_documents.yaml +++ b/targets/hasura/metadata/databases/default/tables/public_documents.yaml @@ -1,6 +1,32 @@ table: name: documents schema: public +configuration: + column_config: + export_id: + custom_name: exportId + custom_column_names: + export_id: exportId + custom_root_fields: {} +object_relationships: + - name: contribution + using: + manual_configuration: + column_mapping: + cdtn_id: cdtn_id + insertion_order: null + remote_table: + name: answers + schema: contribution + - name: export + using: + manual_configuration: + column_mapping: + export_id: id + insertion_order: null + remote_table: + name: export_es_status + schema: public array_relationships: - name: relation_a using: @@ -21,18 +47,19 @@ insert_permissions: permission: check: {} columns: + - cdtn_id + - created_at + - document + - export_id + - initial_id - is_available - is_published - is_searchable - - document - - cdtn_id - - initial_id - meta_description - slug - source - text - title - - created_at - updated_at - role: user permission: @@ -55,18 +82,19 @@ select_permissions: - role: super permission: columns: + - cdtn_id + - created_at + - document + - export_id + - initial_id - is_available - is_published - is_searchable - - document - - cdtn_id - - initial_id - meta_description - slug - source - text - title - - created_at - updated_at filter: {} allow_aggregations: true @@ -92,18 +120,19 @@ update_permissions: - role: super permission: columns: + - cdtn_id + - created_at + - document + - export_id + - initial_id - is_available - is_published - is_searchable - - document - - cdtn_id - - initial_id - meta_description - slug - source - text - title - - created_at - updated_at filter: {} check: {} diff --git a/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/down.sql b/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/down.sql new file mode 100644 index 000000000..9d79d741d --- /dev/null +++ b/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/down.sql @@ -0,0 +1,2 @@ +alter table "public"."documents" drop constraint "documents_export_id_fkey"; +alter table "public"."documents" drop column "export_id"; \ No newline at end of file diff --git a/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/up.sql b/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/up.sql new file mode 100644 index 000000000..d7ee47bdb --- /dev/null +++ b/targets/hasura/migrations/default/1717496582150_alter_table_public_documents_add_column_export_id/up.sql @@ -0,0 +1,7 @@ +alter table "public"."documents" add column "export_id" uuid + null; +alter table "public"."documents" + add constraint "documents_export_id_fkey" + foreign key ("export_id") + references "public"."export_es_status" + ("id") on update restrict on delete restrict; diff --git a/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/down.sql b/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/down.sql new file mode 100644 index 000000000..156d5a41a --- /dev/null +++ b/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "contribution"."answers" add column "cdtn_id" text +-- null; diff --git a/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/up.sql b/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/up.sql new file mode 100644 index 000000000..b46263eca --- /dev/null +++ b/targets/hasura/migrations/default/1717574452015_alter_table_contribution_answers_add_column_cdtn_id/up.sql @@ -0,0 +1,2 @@ +alter table "contribution"."answers" add column "cdtn_id" text + null; diff --git a/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/down.sql b/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/down.sql new file mode 100644 index 000000000..73a819bc7 --- /dev/null +++ b/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/down.sql @@ -0,0 +1 @@ +alter table "contribution"."answers" drop constraint "answers_cdtn_id_fkey"; diff --git a/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/up.sql b/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/up.sql new file mode 100644 index 000000000..2bb11192d --- /dev/null +++ b/targets/hasura/migrations/default/1717574477206_set_fk_contribution_answers_cdtn_id/up.sql @@ -0,0 +1,5 @@ +alter table "contribution"."answers" + add constraint "answers_cdtn_id_fkey" + foreign key ("cdtn_id") + references "public"."documents" + ("cdtn_id") on update set null on delete set null; diff --git a/targets/hasura/migrations/default/1718019634014_rename_status_publish/down.sql b/targets/hasura/migrations/default/1718019634014_rename_status_publish/down.sql new file mode 100644 index 000000000..b98fb5b12 --- /dev/null +++ b/targets/hasura/migrations/default/1718019634014_rename_status_publish/down.sql @@ -0,0 +1,2 @@ +ALTER TYPE statustype +RENAME VALUE 'TO_PUBLISH' TO 'PUBLISHED'; \ No newline at end of file diff --git a/targets/hasura/migrations/default/1718019634014_rename_status_publish/up.sql b/targets/hasura/migrations/default/1718019634014_rename_status_publish/up.sql new file mode 100644 index 000000000..66a90221b --- /dev/null +++ b/targets/hasura/migrations/default/1718019634014_rename_status_publish/up.sql @@ -0,0 +1,2 @@ +ALTER TYPE statustype +RENAME VALUE 'PUBLISHED' TO 'TO_PUBLISH'; \ No newline at end of file diff --git a/targets/hasura/migrations/default/1718022780364_set_export_id_documents_contrib/down.sql b/targets/hasura/migrations/default/1718022780364_set_export_id_documents_contrib/down.sql new file mode 100644 index 000000000..e69de29bb diff --git a/targets/hasura/migrations/default/1718022780364_set_export_id_documents_contrib/up.sql b/targets/hasura/migrations/default/1718022780364_set_export_id_documents_contrib/up.sql new file mode 100644 index 000000000..58e0803ac --- /dev/null +++ b/targets/hasura/migrations/default/1718022780364_set_export_id_documents_contrib/up.sql @@ -0,0 +1,11 @@ +with _last_export as ( + select id from export_es_status ees + where status = 'completed' + order by created_at desc + limit 1 +) +update public.documents d +set export_id = le.id +from _last_export le +where d.source = 'contributions' +and d.export_id is null; \ No newline at end of file diff --git a/targets/hasura/migrations/default/1718025439435_update_cdtn_id_contribution/down.sql b/targets/hasura/migrations/default/1718025439435_update_cdtn_id_contribution/down.sql new file mode 100644 index 000000000..e69de29bb diff --git a/targets/hasura/migrations/default/1718025439435_update_cdtn_id_contribution/up.sql b/targets/hasura/migrations/default/1718025439435_update_cdtn_id_contribution/up.sql new file mode 100644 index 000000000..2ab1dcf4f --- /dev/null +++ b/targets/hasura/migrations/default/1718025439435_update_cdtn_id_contribution/up.sql @@ -0,0 +1,5 @@ +update contribution.answers a +set cdtn_id = d.cdtn_id +from documents d +where d.initial_id = a.id::text +and source = 'contributions'; \ No newline at end of file