本文整理汇总了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);
}
});
示例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;
}
});
示例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;
});
示例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);
});
示例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() };
}
示例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;
}
});
示例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 });
}
}
示例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 () => {}),
};
});
示例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));
};
示例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);
}
});
});
};