-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1308 admin extraction des prqualifis (#1315)
* refactor: prequalified * feat: refonte de la page requêtes préqualifiées * feat: keep only one contained button * fix: build * fix: ts * chore: clean * fix: creation edit failure * fix: memory failure * feat: implementation nouvelle prequalif dans alert-cli * chore: review --------- Co-authored-by: Victor <[email protected]>
- Loading branch information
Showing
53 changed files
with
1,319 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./agreements"; | ||
export * from "./contributions"; | ||
export * from "./global"; | ||
export * from "./prequalified"; |
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,11 @@ | ||
import { DocumentElasticWithSource } from "./global"; | ||
|
||
type Prequalified = { | ||
source: "prequalified"; | ||
variants: string[]; | ||
}; | ||
|
||
export type PrequalifiedElasticDocument = Omit< | ||
DocumentElasticWithSource<Prequalified>, | ||
"slug" | ||
>; |
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
54 changes: 54 additions & 0 deletions
54
targets/alert-cli/src/diff/shared/createDocumentsFetcher.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,54 @@ | ||
import { SourceValues } from "@socialgouv/cdtn-sources"; | ||
import { | ||
AllDocumentsBySourceResult, | ||
AllDocumentsWithRelationBySourceResult, | ||
CountDocumentsBySourceResult, | ||
countDocumentsBySourceQuery, | ||
getAllDocumentsBySourceQuery, | ||
} from "./getDocumentQuery.gql"; | ||
import { gqlClient } from "@shared/utils"; | ||
import { batchPromises } from "../../utils/batch-promises"; | ||
|
||
const PAGE_SIZE = 100; | ||
const JOB_CONCURENCY = 3; | ||
|
||
export const createDocumentsFetcher = | ||
< | ||
T extends | ||
| AllDocumentsBySourceResult | ||
| AllDocumentsWithRelationBySourceResult | ||
>( | ||
gqlRequest = getAllDocumentsBySourceQuery | ||
) => | ||
async (source: SourceValues[]) => { | ||
const countResult = await gqlClient() | ||
.query<CountDocumentsBySourceResult>(countDocumentsBySourceQuery, { | ||
source, | ||
}) | ||
.toPromise(); | ||
|
||
if (countResult.error || !countResult.data) { | ||
console.error(countResult.error && "no data received"); | ||
throw new Error("getSources"); | ||
} | ||
|
||
const { count } = countResult.data.documents_aggregate.aggregate; | ||
|
||
const pages = Array.from( | ||
{ length: Math.ceil(count / PAGE_SIZE) }, | ||
(_, i) => i | ||
); | ||
const documentResults = await batchPromises( | ||
pages, | ||
async (page) => | ||
gqlClient() | ||
.query<T>(gqlRequest, { | ||
limit: PAGE_SIZE, | ||
offset: page * PAGE_SIZE, | ||
source, | ||
}) | ||
.toPromise(), | ||
JOB_CONCURENCY | ||
); | ||
return documentResults; | ||
}; |
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,41 @@ | ||
import { gqlClient } from "@shared/utils"; | ||
import { HasuraDocumentWithRelations } from "./getDocumentQuery.gql"; | ||
|
||
const fetchPrequalifiedQuery = ` | ||
query fetch_prequalified { | ||
search_prequalified { | ||
cdtnId: id | ||
title | ||
contentRelations: documents(order_by: {order: asc}) { | ||
position: order | ||
document { | ||
initialId: initial_id | ||
slug | ||
source | ||
title | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
interface HasuraReturn { | ||
search_prequalified: HasuraDocumentWithRelations[] | undefined; | ||
} | ||
|
||
export async function fetchPrequalified(): Promise< | ||
HasuraDocumentWithRelations[] | undefined | ||
> { | ||
const res = await gqlClient() | ||
.query<HasuraReturn>(fetchPrequalifiedQuery) | ||
.toPromise(); | ||
if (res.error) { | ||
throw res.error; | ||
} | ||
|
||
return res.data?.search_prequalified?.map((prequalif) => ({ | ||
...prequalif, | ||
isPublished: true, | ||
source: "prequalified", | ||
})); | ||
} |
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
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
Oops, something went wrong.