Comment out unused script functions

This commit is contained in:
Ian Philips 2022-09-06 09:27:50 -06:00
parent 5af92a7d81
commit 7c44abdcd7

View File

@ -9,83 +9,83 @@ const getGroups = async () => {
return groups.docs.map((doc) => doc.data() as Group) return groups.docs.map((doc) => doc.data() as Group)
} }
const createContractIdForGroup = async ( // const createContractIdForGroup = async (
groupId: string, // groupId: string,
contractId: string // contractId: string
) => { // ) => {
const firestore = admin.firestore() // const firestore = admin.firestore()
const now = Date.now() // const now = Date.now()
const contractDoc = await firestore // const contractDoc = await firestore
.collection('groups') // .collection('groups')
.doc(groupId) // .doc(groupId)
.collection('groupContracts') // .collection('groupContracts')
.doc(contractId) // .doc(contractId)
.get() // .get()
if (!contractDoc.exists) // if (!contractDoc.exists)
await firestore // await firestore
.collection('groups') // .collection('groups')
.doc(groupId) // .doc(groupId)
.collection('groupContracts') // .collection('groupContracts')
.doc(contractId) // .doc(contractId)
.create({ // .create({
contractId, // contractId,
createdTime: now, // createdTime: now,
}) // })
} // }
const createMemberForGroup = async (groupId: string, userId: string) => { // const createMemberForGroup = async (groupId: string, userId: string) => {
const firestore = admin.firestore() // const firestore = admin.firestore()
const now = Date.now() // const now = Date.now()
const memberDoc = await firestore // const memberDoc = await firestore
.collection('groups') // .collection('groups')
.doc(groupId) // .doc(groupId)
.collection('groupMembers') // .collection('groupMembers')
.doc(userId) // .doc(userId)
.get() // .get()
if (!memberDoc.exists) // if (!memberDoc.exists)
await firestore // await firestore
.collection('groups') // .collection('groups')
.doc(groupId) // .doc(groupId)
.collection('groupMembers') // .collection('groupMembers')
.doc(userId) // .doc(userId)
.create({ // .create({
userId, // userId,
createdTime: now, // createdTime: now,
}) // })
} // }
// async function convertGroupFieldsToGroupDocuments() {
// const groups = await getGroups()
// for (const group of groups) {
// log('updating group', group.slug)
// const groupRef = admin.firestore().collection('groups').doc(group.id)
// const totalMembers = (await groupRef.collection('groupMembers').get()).size
// const totalContracts = (await groupRef.collection('groupContracts').get())
// .size
// if (
// totalMembers === group.memberIds?.length &&
// totalContracts === group.contractIds?.length
// ) {
// log('group already converted', group.slug)
// continue
// }
// const contractStart = totalContracts - 1 < 0 ? 0 : totalContracts - 1
// const membersStart = totalMembers - 1 < 0 ? 0 : totalMembers - 1
// for (const contractId of group.contractIds?.slice(
// contractStart,
// group.contractIds?.length
// ) ?? []) {
// await createContractIdForGroup(group.id, contractId)
// }
// for (const userId of group.memberIds?.slice(
// membersStart,
// group.memberIds?.length
// ) ?? []) {
// await createMemberForGroup(group.id, userId)
// }
// }
// }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function convertGroupFieldsToGroupDocuments() {
const groups = await getGroups()
for (const group of groups) {
log('updating group', group.slug)
const groupRef = admin.firestore().collection('groups').doc(group.id)
const totalMembers = (await groupRef.collection('groupMembers').get()).size
const totalContracts = (await groupRef.collection('groupContracts').get())
.size
if (
totalMembers === group.memberIds?.length &&
totalContracts === group.contractIds?.length
) {
log('group already converted', group.slug)
continue
}
const contractStart = totalContracts - 1 < 0 ? 0 : totalContracts - 1
const membersStart = totalMembers - 1 < 0 ? 0 : totalMembers - 1
for (const contractId of group.contractIds?.slice(
contractStart,
group.contractIds?.length
) ?? []) {
await createContractIdForGroup(group.id, contractId)
}
for (const userId of group.memberIds?.slice(
membersStart,
group.memberIds?.length
) ?? []) {
await createMemberForGroup(group.id, userId)
}
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async function updateTotalContractsAndMembers() { async function updateTotalContractsAndMembers() {
const groups = await getGroups() const groups = await getGroups()