Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
53e97729dc | ||
![]() |
094c6c0c27 |
@@ -0,0 +1,100 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Create Firebase Realtime Database Record',
|
||||||
|
key: 'createFirebaseRealtimeDatabaseRecord',
|
||||||
|
description: 'Creates a child object within your Firebase Realtime Database.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Path',
|
||||||
|
key: 'path',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description:
|
||||||
|
"Indicate the path to the key of the object where the child objects to be queried are located, for example, 'foo/bar/here'.",
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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: 'New ID',
|
||||||
|
key: 'newId',
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'The key to use for this object, or leave it blank for Firebase to create one automatically.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Data',
|
||||||
|
key: 'childData',
|
||||||
|
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($) {
|
||||||
|
let path = $.step.parameters.path;
|
||||||
|
const { convertNumerics, newId, childData } = $.step.parameters;
|
||||||
|
|
||||||
|
if (newId) {
|
||||||
|
path = `${path}/${newId}.json`;
|
||||||
|
} else {
|
||||||
|
path = `${path}.json`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedChildObjectData = childData.reduce((result, entry) => {
|
||||||
|
const key = entry?.key;
|
||||||
|
const value = entry?.value;
|
||||||
|
const isNumber = !isNaN(parseFloat(value));
|
||||||
|
|
||||||
|
if (isNumber && convertNumerics) {
|
||||||
|
result[key] = parseFloat(value);
|
||||||
|
} else {
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const body = formattedChildObjectData;
|
||||||
|
|
||||||
|
const { data } = await $.http.post(path, body, {
|
||||||
|
additionalProperties: {
|
||||||
|
setFirestoreBaseUrl: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,32 @@
|
|||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Find Firebase Realtime Database Record',
|
||||||
|
key: 'findFirebaseRealtimeDatabaseRecord',
|
||||||
|
description: 'Finds a child object in Firebase Realtime Database.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Path',
|
||||||
|
key: 'path',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description:
|
||||||
|
"Indicate the path to the key of the object where the child objects to be queried are located, for example, 'foo/bar/here'.",
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const { path } = $.step.parameters;
|
||||||
|
|
||||||
|
const { data } = await $.http.get(`${path}.json`, {
|
||||||
|
additionalProperties: {
|
||||||
|
setFirestoreBaseUrl: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -1,4 +1,11 @@
|
|||||||
import createCloudFirestoreDocument from './create-cloud-firestore-document/index.js';
|
import createCloudFirestoreDocument from './create-cloud-firestore-document/index.js';
|
||||||
|
import createFirebaseRealtimeDatabaseRecord from './create-firebase-realtime-database-record/index.js';
|
||||||
import findCloudFirestoreDocument from './find-cloud-firestore-document/index.js';
|
import findCloudFirestoreDocument from './find-cloud-firestore-document/index.js';
|
||||||
|
import findFirebaseRealtimeDatabaseRecord from './find-firebase-realtime-database-record/index.js';
|
||||||
|
|
||||||
export default [createCloudFirestoreDocument, findCloudFirestoreDocument];
|
export default [
|
||||||
|
createCloudFirestoreDocument,
|
||||||
|
createFirebaseRealtimeDatabaseRecord,
|
||||||
|
findCloudFirestoreDocument,
|
||||||
|
findFirebaseRealtimeDatabaseRecord,
|
||||||
|
];
|
||||||
|
@@ -3,8 +3,12 @@ favicon: /favicons/firebase.svg
|
|||||||
items:
|
items:
|
||||||
- name: Create Cloud Firestore document
|
- name: Create Cloud Firestore document
|
||||||
desc: Creates a new document within a Cloud Firestore collection.
|
desc: Creates a new document within a Cloud Firestore collection.
|
||||||
|
- name: Create Firebase Realtime Database Record
|
||||||
|
desc: Creates a child object within your Firebase Realtime Database.
|
||||||
- name: Find Cloud Firestore document
|
- name: Find Cloud Firestore document
|
||||||
desc: Finds a document within a collection.
|
desc: Finds a document within a collection.
|
||||||
|
- name: Find Firebase Realtime Database Record
|
||||||
|
desc: Finds a child object in Firebase Realtime Database.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user