chore: only set visibility for container particles
This commit is contained in:
+6
-3
@@ -67,12 +67,18 @@ export const StreamPropertiesSchema = z.object({
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
status: z.enum(["open", "closed"]),
|
status: z.enum(["open", "closed"]),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
|
// e.g. ["human:[email protected]", "human:[email protected]"] - visible only to Aron and John
|
||||||
|
// e.g. ["network:123"] - visible to everyone in the network
|
||||||
|
visible_to: z.array(z.string())
|
||||||
});
|
});
|
||||||
export type StreamProperties = z.infer<typeof StreamPropertiesSchema>;
|
export type StreamProperties = z.infer<typeof StreamPropertiesSchema>;
|
||||||
|
|
||||||
export const FolderPropertiesSchema = z.object({
|
export const FolderPropertiesSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
color: z.string().optional(),
|
color: z.string().optional(),
|
||||||
|
// e.g. ["human:[email protected]", "human:[email protected]"] - visible only to Aron and John
|
||||||
|
// e.g. ["network:123"] - visible to everyone in the network
|
||||||
|
visible_to: z.array(z.string())
|
||||||
});
|
});
|
||||||
export type FolderProperties = z.infer<typeof FolderPropertiesSchema>;
|
export type FolderProperties = z.infer<typeof FolderPropertiesSchema>;
|
||||||
|
|
||||||
@@ -128,9 +134,6 @@ const ParticleBaseSchema = z.object({
|
|||||||
created_at: z.coerce.date(),
|
created_at: z.coerce.date(),
|
||||||
created_by_email: z.string().email(),
|
created_by_email: z.string().email(),
|
||||||
updated_at: z.coerce.date().optional(),
|
updated_at: z.coerce.date().optional(),
|
||||||
// e.g. ["human:[email protected]", "human:[email protected]"] - visible only to Aron and John
|
|
||||||
// e.g. ["network:123"] - visible to everyone in the network
|
|
||||||
visible_to: z.array(z.string())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ParticleSchema = z.discriminatedUnion("type", [
|
export const ParticleSchema = z.discriminatedUnion("type", [
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ export async function createParticle<T extends ParticleType>(
|
|||||||
type: T,
|
type: T,
|
||||||
properties: ParticlePropertiesMap[T],
|
properties: ParticlePropertiesMap[T],
|
||||||
createdByEmail: string,
|
createdByEmail: string,
|
||||||
visibleTo: string[],
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const particle: Particle = ParticleSchema.parse({
|
const particle: Particle = ParticleSchema.parse({
|
||||||
id: "", // ignored by toFirestore, but needed to satisfy the type
|
id: "", // ignored by toFirestore, but needed to satisfy the type
|
||||||
@@ -101,7 +100,6 @@ export async function createParticle<T extends ParticleType>(
|
|||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
created_by_email: createdByEmail,
|
created_by_email: createdByEmail,
|
||||||
updated_at: null,
|
updated_at: null,
|
||||||
visible_to: visibleTo,
|
|
||||||
});
|
});
|
||||||
const ref = await addDoc(typedCollection(collectionPath), particle);
|
const ref = await addDoc(typedCollection(collectionPath), particle);
|
||||||
return ref.id;
|
return ref.id;
|
||||||
@@ -111,7 +109,6 @@ export async function createParticle<T extends ParticleType>(
|
|||||||
export async function updateParticle<T extends ParticleType>(
|
export async function updateParticle<T extends ParticleType>(
|
||||||
docPath: string,
|
docPath: string,
|
||||||
properties: Partial<ParticlePropertiesMap[T]>,
|
properties: Partial<ParticlePropertiesMap[T]>,
|
||||||
visibleTo?: string[],
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const particleRef = typedDoc(docPath);
|
const particleRef = typedDoc(docPath);
|
||||||
// Take the partial and create a new object with dot notation
|
// Take the partial and create a new object with dot notation
|
||||||
@@ -123,6 +120,5 @@ export async function updateParticle<T extends ParticleType>(
|
|||||||
await updateDoc(particleRef, {
|
await updateDoc(particleRef, {
|
||||||
...updatedProperties,
|
...updatedProperties,
|
||||||
updated_at: serverTimestamp(),
|
updated_at: serverTimestamp(),
|
||||||
...(visibleTo ? { visible_to: visibleTo } : {}),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user