integrate visibility to particles

This commit is contained in:
talksik
2026-03-17 16:54:09 -07:00
parent 58c6e8a01a
commit d84a49fb5b
3 changed files with 11 additions and 1 deletions
+5
View File
@@ -41,6 +41,7 @@ const particleConverter: FirestoreDataConverter<Particle> = {
created_at: (raw.created_at as Timestamp).toDate(),
created_by_email: raw.created_by_email,
updated_at: raw.updated_at ? (raw.updated_at as Timestamp).toDate() : undefined,
visible_to: raw.visible_to,
});
},
};
@@ -91,6 +92,7 @@ export async function createParticle<T extends ParticleType>(
type: T,
properties: ParticlePropertiesMap[T],
createdByEmail: string,
visibleTo: string[],
): Promise<string> {
const particle: Particle = ParticleSchema.parse({
id: "", // ignored by toFirestore, but needed to satisfy the type
@@ -99,6 +101,7 @@ export async function createParticle<T extends ParticleType>(
created_at: new Date(),
created_by_email: createdByEmail,
updated_at: null,
visible_to: visibleTo,
});
const ref = await addDoc(typedCollection(collectionPath), particle);
return ref.id;
@@ -108,6 +111,7 @@ export async function createParticle<T extends ParticleType>(
export async function updateParticle<T extends ParticleType>(
docPath: string,
properties: Partial<ParticlePropertiesMap[T]>,
visibleTo?: string[],
): Promise<void> {
const particleRef = typedDoc(docPath);
// Take the partial and create a new object with dot notation
@@ -119,5 +123,6 @@ export async function updateParticle<T extends ParticleType>(
await updateDoc(particleRef, {
...updatedProperties,
updated_at: serverTimestamp(),
...(visibleTo ? { visible_to: visibleTo } : {}),
});
}