Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d6b9410932 |
@@ -0,0 +1,116 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Create Cloud Firestore document',
|
||||||
|
key: 'createCloudFirestoreDocument',
|
||||||
|
description: 'Creates a new document within a Cloud Firestore collection.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Collection',
|
||||||
|
key: 'collectionId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listFirestoreCollections',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Convert Numerics',
|
||||||
|
key: 'convertNumerics',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
"If any value represents a valid numerical value, whether it's an integer or a floating-point number, this field directs the database to store it as a numeric data type instead of a string.",
|
||||||
|
variables: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'Yes', value: true },
|
||||||
|
{ label: 'No', value: false },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Document ID',
|
||||||
|
key: 'documentId',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'The document ID to use for this document. If not specified, an ID will be assigned.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Document Data',
|
||||||
|
key: 'documentData',
|
||||||
|
type: 'dynamic',
|
||||||
|
required: false,
|
||||||
|
description: '',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label: 'Key',
|
||||||
|
key: 'key',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Value',
|
||||||
|
key: 'value',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const projectId = $.auth.data.projectId;
|
||||||
|
const { collectionId, documentId, documentData, convertNumerics } =
|
||||||
|
$.step.parameters;
|
||||||
|
|
||||||
|
const documentDataObject = documentData.reduce((result, entry) => {
|
||||||
|
const key = entry.key?.toLowerCase();
|
||||||
|
const value = entry.value;
|
||||||
|
const isNumber = !isNaN(parseFloat(value));
|
||||||
|
|
||||||
|
if (key && value) {
|
||||||
|
const formattedValue =
|
||||||
|
convertNumerics && isNumber
|
||||||
|
? { integerValue: parseFloat(value) }
|
||||||
|
: { stringValue: value };
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[key]: formattedValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
fields: documentDataObject,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.post(
|
||||||
|
`/v1/projects/${projectId}/databases/(default)/documents/${collectionId}?documentId=${documentId}`,
|
||||||
|
body,
|
||||||
|
{
|
||||||
|
additionalProperties: {
|
||||||
|
setFirestoreBaseUrl: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
3
packages/backend/src/apps/firebase/actions/index.js
Normal file
3
packages/backend/src/apps/firebase/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import createCloudFirestoreDocument from './create-cloud-firestore-document/index.js';
|
||||||
|
|
||||||
|
export default [createCloudFirestoreDocument];
|
@@ -4,6 +4,7 @@ import auth from './auth/index.js';
|
|||||||
import setBaseUrl from './common/set-base-url.js';
|
import setBaseUrl from './common/set-base-url.js';
|
||||||
import triggers from './triggers/index.js';
|
import triggers from './triggers/index.js';
|
||||||
import dynamicData from './dynamic-data/index.js';
|
import dynamicData from './dynamic-data/index.js';
|
||||||
|
import actions from './actions/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Firebase',
|
name: 'Firebase',
|
||||||
@@ -18,4 +19,5 @@ export default defineApp({
|
|||||||
auth,
|
auth,
|
||||||
triggers,
|
triggers,
|
||||||
dynamicData,
|
dynamicData,
|
||||||
|
actions,
|
||||||
});
|
});
|
||||||
|
@@ -100,6 +100,7 @@ export default defineConfig({
|
|||||||
collapsible: true,
|
collapsible: true,
|
||||||
collapsed: true,
|
collapsed: true,
|
||||||
items: [
|
items: [
|
||||||
|
{ text: 'Actions', link: '/apps/firebase/actions' },
|
||||||
{ text: 'Triggers', link: '/apps/firebase/triggers' },
|
{ text: 'Triggers', link: '/apps/firebase/triggers' },
|
||||||
{ text: 'Connection', link: '/apps/firebase/connection' },
|
{ text: 'Connection', link: '/apps/firebase/connection' },
|
||||||
],
|
],
|
||||||
|
12
packages/docs/pages/apps/firebase/actions.md
Normal file
12
packages/docs/pages/apps/firebase/actions.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/firebase.svg
|
||||||
|
items:
|
||||||
|
- name: Create Cloud Firestore document
|
||||||
|
desc: Creates a new document within a Cloud Firestore collection.
|
||||||
|
---
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import CustomListing from '../../components/CustomListing.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CustomListing />
|
Reference in New Issue
Block a user