当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript firebase-admin.firestore函数代码示例

本文整理汇总了TypeScript中firebase-admin.firestore函数的典型用法代码示例。如果您正苦于以下问题:TypeScript firestore函数的具体用法?TypeScript firestore怎么用?TypeScript firestore使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了firestore函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: catch

  .firestore.document('/teams/{teamId}').onDelete(async (change, context) => {

    console.log(context.params.teamId);

    try {

      // als Team der Woche Eintrag löschen
      const totWSnapshot = await admin.firestore().collection('team-of-the-month')
        .where('assignedTeamId', '==', context.params.teamId)
        .get();

      totWSnapshot.forEach(async (doc) => {
        await admin.firestore().doc('team-of-the-month/' + doc.data().id).delete();
      });

      // Spiele dieser Mannschaft löschen
      const matchesSnapshot = await admin.firestore().collection('matches')
        .where('assignedTeam', '==', context.params.teamId)
        .get();

      matchesSnapshot.docs.forEach(async (doc) => {
        await admin.firestore().doc('matches/' + doc.data().id).delete();
      });

    } catch (e) {
      console.log(e);
    }

  });
开发者ID:Meistercoach83,项目名称:sfw,代码行数:29,代码来源:team-deleted.ts

示例2: moment

  .onPublish(async () => {

    try {
      const applicationsSnapshot = await admin.firestore().collection('applications')
        .where('isCurrentApplication', '==', true)
        .get();
      const currentApp = applicationsSnapshot.docs[0].data();

      const teamOfTheWeekMailing = currentApp.mailing.filter(mailing => {
        return mailing.isActive && mailing.title === 'Mannschaft des Monats';
      });

      if (teamOfTheWeekMailing && teamOfTheWeekMailing.length > 0) {

        const teamsSnapshot = await admin.firestore().collection('teams').get();

        const sample = teamsSnapshot.docs[Math.floor(Math.random() * teamsSnapshot.size)];

        await admin.firestore().collection(collectionString)
          .doc(now.format('YYYY') + '-' + now.month())
          .create({
            assignedTeamId: sample.data().id,
            title: now.format('YYYY') + '-' + now.month()
          });

        const current = moment().add(1, 'month');

        const msg = {
          to: teamOfTheWeekMailing[0].emails,
          from: 'mitglieder@sfwinterbach.com',
          subject: 'Mannschaft des Monats ' + now.format('MM') + '.' + now.format('YYYY'),
          templateId: 'cd68a992-a76c-4b47-8dda-a7d9c68fd1b3',
          substitutionWrappers: ['{{', '}}'],
          substitutions: {
            adminName: 'Thomas',
            teamName: sample.data().title + ' (' + sample.data().subTitle + ')',
            monthString: current.month() + '.' + now.format('YYYY')
          }
        };
        return sgMail.send(msg);
      } else {
        console.warn('Kein Mail-Verteiler mit dem Namen "Mannschaft des Monats" gefunden');
        return true;
      }
    } catch (e) {
      console.error(e);
      return e;
    }
  });
开发者ID:Meistercoach83,项目名称:sfw,代码行数:49,代码来源:team-of-the-month.ts

示例3: catch

  .firestore.document('/members/{memberId}').onDelete(async (change, context) => {

    const memberId = context.params.memberId;

    const groups = ['ah', 'club', 'honorary', 'player'];

    try {

      for (const group of groups) {
        const motWSnapshot = await admin.firestore().collection('member-of-the-week')
          .where(group + '.assignedMemberId', '==', memberId)
          .get();

        motWSnapshot.forEach(async (doc) => {
          await admin.firestore().doc('member-of-the-week/' + doc.data().id).delete();
        });
      }

      // als Ehrenmitglied löschen

      // als Vorstandsmitglied löschen

      // als Trainer, Betreuer etc. löschen

      // als Spieler einer Mannschaft löschen
      const teamsSnapshot = await admin.firestore().collection('teams')
        .where('assignedPlayers', 'array-contains', memberId)
        .get();

      teamsSnapshot.docs.forEach(async (doc) => {
        const data = doc.data();
        console.log(data.assignedPlayers);
        data.assignedPlayers.splice(data.assignedPlayers.indexOf(memberId), 1);
        console.log(data.assignedPlayers);
        await admin.firestore().doc('teams/' + doc.data().id + '').update(data);
      });


      // in Aufstellungen löschen
      // in Auswechselungen und Kommentaren löschen

    } catch (e) {
      console.log(e);
    }

    return true;

  });
开发者ID:Meistercoach83,项目名称:sfw,代码行数:48,代码来源:member-deleted.ts

示例4:

 teamsSnapshot.docs.forEach(async (doc) => {
   const data = doc.data();
   console.log(data.assignedPlayers);
   data.assignedPlayers.splice(data.assignedPlayers.indexOf(memberId), 1);
   console.log(data.assignedPlayers);
   await admin.firestore().doc('teams/' + doc.data().id + '').update(data);
 });
开发者ID:Meistercoach83,项目名称:sfw,代码行数:7,代码来源:member-deleted.ts

示例5: initializeApp

 /**
  * Initialize Firebase App
  *
  * @param {any} serviceAccount
  * @param {any} databaseURL
  */
 initializeApp(serviceAccount: string, databaseURL: string) {
     admin.initializeApp({
         credential: admin.credential.cert(serviceAccount),
         databaseURL: databaseURL
     });
     return { 'firestore': admin.firestore() };
 }
开发者ID:ansidev,项目名称:firebase-functions-helper,代码行数:13,代码来源:firebase.ts

示例6: join

  .onCreate(async (snapshot, context) => {

    try {

      // const bucketName = admin.storage().bucket().name;
      /* const gcs = new Storage({
        bucketName
      }); */

      const reportId = context.params.reportId;

      const db = admin.firestore();
      const reportRef = db.collection('reports').doc(reportId);

      const reportSnapshot = await reportRef.get();
      const data = reportSnapshot.data();

      const fileName = `reports/${data.type}/${reportId}.xslx`;

      const destination = join(tmpdir(), 'exports');
      const tempFilePath = join(destination, fileName);

      await fs.ensureDir(tempFilePath);

      console.log(`Writing out to ${tempFilePath}`);
      fs.writeFileSync(tempFilePath, 'something!');

      return admin.storage().bucket()
        .upload(tempFilePath, { destination })
        .then(() => fs.unlinkSync(tempFilePath))
        .catch(err => console.error('ERROR inside upload: ', err));

      /*
        const contentListSnapshot = await db.collection(data.type).get();
  
        const contentData = [];
        contentListSnapshot.docs.forEach((doc) => {
          contentData.push(doc.data());
        });
  
        try {
          // await file.createWriteStream().write(Buffer.from(contentData));
          return await reportRef.update({ status: 'complete' });
  
        } catch (e) {
          console.log(e);
        } */

    } catch (e) {
      console.log(e);
      return e;
    }

  });
开发者ID:Meistercoach83,项目名称:sfw,代码行数:54,代码来源:export-data-to-pdf.ts

示例7: async

 async (req: any, res: any) => {
   try {
     await admin
       .firestore()
       .collection("test")
       .add({ date: new Date() });
     res.json({ from_trigger: true });
   } catch (e) {
     res.json({ error: e.message });
   }
 }
开发者ID:firebase,项目名称:firebase-tools,代码行数:11,代码来源:functionsEmulatorRuntime.spec.ts

示例8: InvokeRuntimeWithFunctions

        const runtime = InvokeRuntimeWithFunctions(FunctionRuntimeBundles.onCreate, () => {
          const admin = require("firebase-admin");
          admin.initializeApp();
          admin.firestore().settings({
            timestampsInSnapshots: true,
          });

          return {
            function_id: require("firebase-functions")
              .firestore.document("test/test")
              // tslint:disable-next-line:no-empty
              .onCreate(async () => {}),
          };
        });
开发者ID:firebase,项目名称:firebase-tools,代码行数:14,代码来源:functionsEmulatorRuntime.spec.ts

示例9: async

export const exportFirestore = async (foldername: string) => {
  const firestore = admin.firestore();
  firestore.settings({ timestampsInSnapshots: true });
  const collections = await firestore.getCollections();
  const data = {};
  for (let collection of collections) {
    const test = await firestore.collection(collection.id).get();
    data[collection.id] = {};
    test.forEach(doc => {
      data[collection.id][doc.id] = doc.data();
    });
  }
  writeFileSync(foldername, JSON.stringify(data, null, 2));
};
开发者ID:accosine,项目名称:poltergeist,代码行数:14,代码来源:backup.ts

示例10: async

export const importFirestore = async (foldername: string) => {
  const data = JSON.parse(readFileSync(foldername, 'utf8'));
  const firestore = admin.firestore();
  firestore.settings({ timestampsInSnapshots: true });

  Object.entries(data).forEach(([collection, value]) => {
    Object.entries(value).forEach(async ([name, content]) => {
      try {
        console.log('set', collection, name);
        await firestore
          .collection(collection)
          .doc(name)
          .set(content);
      } catch (error) {
        console.log(error);
      }
    });
  });
};
开发者ID:accosine,项目名称:poltergeist,代码行数:19,代码来源:restore.ts


注:本文中的firebase-admin.firestore函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。