Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute des infos sur la connexion à Grist #4197

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/grist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const baseURL = "grist.incubateur.net"
const tableId = "Veille"

export function Grist(docId, apiKey) {
const docUrl = `https://${baseURL}/api/docs/${docId}`
const apiUrl = `https://${baseURL}/api`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas possible de mettre ceci dans le .env ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Au même titre que j'ai ajouté un log pour savoir avec quel user on est connecté, je me dis que c'est pas si mal d'avoir l'instance directement dans le code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, je trouve que c'est dommage car la baseUrl est utilisée à deux endroits donc si l'url change il faudra la modifier deux fois

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const docUrl = `${apiUrl}/docs/${docId}`
const recordsUrl = `${docUrl}/tables/${tableId}/records`
const gristConfig = {
headers: {
Expand All @@ -15,6 +16,10 @@ export function Grist(docId, apiKey) {
}

const g = {
getConnectedUser: async () => {
const response = await axios.get(`${apiUrl}/profile/user`, gristConfig)
return response.data
},
get: async (filter?: any) => {
let url = recordsUrl
if (filter) {
Expand Down
8 changes: 6 additions & 2 deletions tools/check-links-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ async function main() {
throw new Error("Missing GRIST_API_KEY")
}
const gristAPI = Grist(process.env.GRIST_DOC_ID, process.env.GRIST_API_KEY)

const user = await gristAPI.getConnectedUser()
console.log(`Connected as ${user.name}.`)

const rawExistingWarnings = await gristAPI.get({
Corrige: [false],
Aide: benefitIdsFromCLI,
Expand Down Expand Up @@ -206,8 +210,8 @@ async function main() {
pullRequestURL
)
)
type recordsByOperationTypesType = { [operationType: string]: GristData[] }
const recordsByOperationTypes: recordsByOperationTypesType = {
type RecordsByOperationTypesType = { [operationType: string]: GristData[] }
const recordsByOperationTypes: RecordsByOperationTypesType = {
add: [],
update: [],
}
Expand Down
Loading