feat(google-forms): add list forms dynamic data

This commit is contained in:
Ali BARIN
2023-01-03 19:34:23 +01:00
parent 3fc7fce9ca
commit 0b52a1bd01
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import listForms from './list-forms';
export default [listForms];

View File

@@ -0,0 +1,34 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List forms',
key: 'listForms',
async run($: IGlobalVariable) {
const forms: {
data: IJSONObject[];
} = {
data: [],
};
const params = {
q: `mimeType='application/vnd.google-apps.form'`,
spaces: 'drive',
pageToken: undefined as unknown as string,
};
do {
const { data } = await $.http.get(`https://www.googleapis.com/drive/v3/files`, { params });
params.pageToken = data.nextPageToken;
for (const file of data.files) {
forms.data.push({
value: file.id,
name: file.name,
});
}
} while (params.pageToken);
return forms;
},
};

View File

@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app'; import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header'; import addAuthHeader from './common/add-auth-header';
import auth from './auth'; import auth from './auth';
import dynamicData from './dynamic-data';
export default defineApp({ export default defineApp({
name: 'Google Forms', name: 'Google Forms',
@@ -13,4 +14,5 @@ export default defineApp({
supportsConnections: true, supportsConnections: true,
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
dynamicData,
}); });