diff --git a/functions/src/firestore-documents/chatMessage.flutterfireGen.ts b/functions/src/firestore-documents/chatMessage.flutterfireGen.ts new file mode 100644 index 00000000..e183be3d --- /dev/null +++ b/functions/src/firestore-documents/chatMessage.flutterfireGen.ts @@ -0,0 +1,532 @@ +import * as admin from 'firebase-admin' +import { + CollectionReference, + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export type ChatMessageType = `worker` | `host` | `system` + +export class ReadChatMessage { + constructor({ + chatMessageId, + path, + senderId, + chatMessageType, + content, + imageUrls, + isDeleted, + createdAt, + updatedAt + }: { + chatMessageId: string + path: string + senderId: string + chatMessageType: ChatMessageType + content: string + imageUrls: string[] + isDeleted: boolean + createdAt?: Date + updatedAt?: Date + }) { + this.chatMessageId = chatMessageId + this.path = path + this.senderId = senderId + this.chatMessageType = chatMessageType + this.content = content + this.imageUrls = imageUrls + this.isDeleted = isDeleted + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly chatMessageId: string + + readonly path: string + + readonly senderId: string + + readonly chatMessageType: ChatMessageType + + readonly content: string + + readonly imageUrls: string[] + + readonly isDeleted: boolean + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static chatMessageTypeConverterFromJson( + chatMessageType: string + ): ChatMessageType { + return chatMessageType as ChatMessageType + } + + private static fromJson(json: Record): ReadChatMessage { + return new ReadChatMessage({ + chatMessageId: json[`chatMessageId`] as string, + path: json[`path`] as string, + senderId: json[`senderId`] as string, + chatMessageType: ReadChatMessage.chatMessageTypeConverterFromJson( + json[`chatMessageType`] as string + ), + content: (json[`content`] as string | undefined) ?? ``, + imageUrls: + (json[`imageUrls`] as unknown[] | undefined)?.map( + (e) => e as string + ) ?? [], + isDeleted: (json[`isDeleted`] as boolean | undefined) ?? false, + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadChatMessage { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadChatMessage.fromJson({ + ...cleanedData, + chatMessageId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateChatMessage { + constructor({ + senderId, + chatMessageType, + content, + imageUrls, + isDeleted + }: { + senderId: string + chatMessageType: ChatMessageType + content: string + imageUrls: string[] + isDeleted: boolean + }) { + this.senderId = senderId + this.chatMessageType = chatMessageType + this.content = content + this.imageUrls = imageUrls + this.isDeleted = isDeleted + } + + readonly senderId: string + + readonly chatMessageType: ChatMessageType + + readonly content: string + + readonly imageUrls: string[] + + readonly isDeleted: boolean + + private static chatMessageTypeConverterToJson( + chatMessageType: ChatMessageType + ): string { + return chatMessageType as string + } + + toJson(): Record { + return { + senderId: this.senderId, + chatMessageType: CreateChatMessage.chatMessageTypeConverterToJson( + this.chatMessageType + ), + content: this.content, + imageUrls: this.imageUrls, + isDeleted: this.isDeleted, + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateChatMessage { + constructor({ + senderId, + chatMessageType, + content, + imageUrls, + isDeleted, + createdAt + }: { + senderId?: string + chatMessageType?: ChatMessageType + content?: string + imageUrls?: string[] + isDeleted?: boolean + createdAt?: Date + }) { + this.senderId = senderId + this.chatMessageType = chatMessageType + this.content = content + this.imageUrls = imageUrls + this.isDeleted = isDeleted + this.createdAt = createdAt + } + + readonly senderId?: string + + readonly chatMessageType?: ChatMessageType + + readonly content?: string + + readonly imageUrls?: string[] + + readonly isDeleted?: boolean + + readonly createdAt?: Date + + private static chatMessageTypeConverterToJson( + chatMessageType: ChatMessageType + ): string { + return chatMessageType as string + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.senderId != undefined) { + json[`senderId`] = this.senderId + } + if (this.chatMessageType != undefined) { + json[`chatMessageType`] = + UpdateChatMessage.chatMessageTypeConverterToJson( + this.chatMessageType + ) + } + if (this.content != undefined) { + json[`content`] = this.content + } + if (this.imageUrls != undefined) { + json[`imageUrls`] = this.imageUrls + } + if (this.isDeleted != undefined) { + json[`isDeleted`] = this.isDeleted + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteChatMessage {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the chatMessages collection for reading. + */ +export const readChatMessageCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`chatMessages`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadChatMessage => { + return ReadChatMessage.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadChatMessage` + ) + } + }) +} + +/** + * Provides a reference to a chatMessage document for reading. + * @param chatMessageId - The ID of the chatMessage document to read. + */ +export const readChatMessageDocumentReference = ({ + chatRoomId, + chatMessageId +}: { + chatRoomId: string + chatMessageId: string +}): DocumentReference => + readChatMessageCollectionReference({ + chatRoomId + }).doc(chatMessageId) + +/** + * Provides a reference to the chatMessages collection for creating. + */ +export const createChatMessageCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`chatMessages`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateChatMessage` + ) + }, + toFirestore: (obj: CreateChatMessage): DocumentData => { + return obj.toJson() + } + }) +} + +/** + * Provides a reference to a chatMessage document for creating. + * @param chatMessageId - The ID of the chatMessage document to read. + */ +export const createChatMessageDocumentReference = ({ + chatRoomId, + chatMessageId +}: { + chatRoomId: string + chatMessageId: string +}): DocumentReference => + createChatMessageCollectionReference({ + chatRoomId + }).doc(chatMessageId) + +/** + * Provides a reference to the chatMessages collection for updating. + */ +export const updateChatMessageCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`chatMessages`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateChatMessage` + ) + }, + toFirestore: (obj: UpdateChatMessage): DocumentData => { + return obj.toJson() + } + }) +} + +/** + * Provides a reference to a chatMessage document for updating. + * @param chatMessageId - The ID of the chatMessage document to read. + */ +export const updateChatMessageDocumentReference = ({ + chatRoomId, + chatMessageId +}: { + chatRoomId: string + chatMessageId: string +}): DocumentReference => + updateChatMessageCollectionReference({ + chatRoomId + }).doc(chatMessageId) + +/** + * Provides a reference to the chatMessages collection for deleting. + */ +export const deleteChatMessageCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`chatMessages`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteChatMessage` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteChatMessage` + ) + } + }) +} + +/** + * Provides a reference to a chatMessage document for deleting. + * @param chatMessageId - The ID of the chatMessage document to read. + */ +export const deleteChatMessageDocumentReference = ({ + chatRoomId, + chatMessageId +}: { + chatRoomId: string + chatMessageId: string +}): DocumentReference => + deleteChatMessageCollectionReference({ + chatRoomId + }).doc(chatMessageId) + +/** + * Manages queries against the chatMessages collection. + */ +export class ChatMessageQuery { + /** + * Fetches chatMessage documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + chatRoomId, + queryBuilder, + compare + }: { + chatRoomId: string + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadChatMessage, rhs: ReadChatMessage) => number + }): Promise { + let query: Query = readChatMessageCollectionReference({ + chatRoomId + }) + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific chatMessage document. + * @param chatMessageId - The ID of the chatMessage document to fetch. + */ + async fetchDocument({ + chatRoomId, + chatMessageId + }: { + chatRoomId: string + chatMessageId: string + }): Promise { + const ds = await readChatMessageDocumentReference({ + chatRoomId, + chatMessageId + }).get() + return ds.data() + } + + /** + * Adds a chatMessage document. + * @param createChatMessage - The chatMessage details to add. + */ + async add({ + chatRoomId, + createChatMessage + }: { + chatRoomId: string + createChatMessage: CreateChatMessage + }): Promise> { + return createChatMessageCollectionReference({ chatRoomId }).add( + createChatMessage + ) + } + + /** + * Sets a chatMessage document. + * @param chatMessageId - The ID of the chatMessage document to set. + * @param createChatMessage - The chatMessage details to set. + * @param options - Options for the set operation. + */ + async set({ + chatRoomId, + chatMessageId, + createChatMessage, + options + }: { + chatRoomId: string + chatMessageId: string + createChatMessage: CreateChatMessage + options?: SetOptions + }): Promise { + if (options == undefined) { + return createChatMessageDocumentReference({ + chatRoomId, + chatMessageId + }).set(createChatMessage) + } else { + return createChatMessageDocumentReference({ + chatRoomId, + chatMessageId + }).set(createChatMessage, options) + } + } + + /** + * Updates a specific chatMessage document. + * @param chatMessageId - The ID of the chatMessage document to update. + * @param updateChatMessage - The details for updating the chatMessage. + */ + async update({ + chatRoomId, + chatMessageId, + updateChatMessage + }: { + chatRoomId: string + chatMessageId: string + updateChatMessage: UpdateChatMessage + }): Promise { + return updateChatMessageDocumentReference({ + chatRoomId, + chatMessageId + }).update(updateChatMessage.toJson()) + } + + /** + * Deletes a specific chatMessage document. + * @param chatMessageId - The ID of the chatMessage document to delete. + */ + async delete({ + chatRoomId, + chatMessageId + }: { + chatRoomId: string + chatMessageId: string + }): Promise { + return deleteChatMessageDocumentReference({ + chatRoomId, + chatMessageId + }).delete() + } +} diff --git a/functions/src/firestore-documents/chatRoom.flutterfireGen.ts b/functions/src/firestore-documents/chatRoom.flutterfireGen.ts new file mode 100644 index 00000000..e0eb2871 --- /dev/null +++ b/functions/src/firestore-documents/chatRoom.flutterfireGen.ts @@ -0,0 +1,358 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadChatRoom { + constructor({ + chatRoomId, + path, + workerId, + hostId, + createdAt, + updatedAt + }: { + chatRoomId: string + path: string + workerId: string + hostId: string + createdAt?: Date + updatedAt?: Date + }) { + this.chatRoomId = chatRoomId + this.path = path + this.workerId = workerId + this.hostId = hostId + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly chatRoomId: string + + readonly path: string + + readonly workerId: string + + readonly hostId: string + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static fromJson(json: Record): ReadChatRoom { + return new ReadChatRoom({ + chatRoomId: json[`chatRoomId`] as string, + path: json[`path`] as string, + workerId: json[`workerId`] as string, + hostId: json[`hostId`] as string, + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadChatRoom { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadChatRoom.fromJson({ + ...cleanedData, + chatRoomId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateChatRoom { + constructor({ workerId, hostId }: { workerId: string; hostId: string }) { + this.workerId = workerId + this.hostId = hostId + } + + readonly workerId: string + + readonly hostId: string + + toJson(): Record { + return { + workerId: this.workerId, + hostId: this.hostId, + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateChatRoom { + constructor({ + workerId, + hostId, + createdAt + }: { + workerId?: string + hostId?: string + createdAt?: Date + }) { + this.workerId = workerId + this.hostId = hostId + this.createdAt = createdAt + } + + readonly workerId?: string + + readonly hostId?: string + + readonly createdAt?: Date + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.workerId != undefined) { + json[`workerId`] = this.workerId + } + if (this.hostId != undefined) { + json[`hostId`] = this.hostId + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteChatRoom {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the chatRooms collection for reading. + */ +export const readChatRoomCollectionReference = db + .collection(`chatRooms`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadChatRoom => { + return ReadChatRoom.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error(`toFirestore is not implemented for ReadChatRoom`) + } + }) + +/** + * Provides a reference to a chatRoom document for reading. + * @param chatRoomId - The ID of the chatRoom document to read. + */ +export const readChatRoomDocumentReference = ({ + chatRoomId +}: { + chatRoomId: string +}): DocumentReference => + readChatRoomCollectionReference.doc(chatRoomId) + +/** + * Provides a reference to the chatRooms collection for creating. + */ +export const createChatRoomCollectionReference = db + .collection(`chatRooms`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateChatRoom` + ) + }, + toFirestore: (obj: CreateChatRoom): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a chatRoom document for creating. + * @param chatRoomId - The ID of the chatRoom document to read. + */ +export const createChatRoomDocumentReference = ({ + chatRoomId +}: { + chatRoomId: string +}): DocumentReference => + createChatRoomCollectionReference.doc(chatRoomId) + +/** + * Provides a reference to the chatRooms collection for updating. + */ +export const updateChatRoomCollectionReference = db + .collection(`chatRooms`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateChatRoom` + ) + }, + toFirestore: (obj: UpdateChatRoom): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a chatRoom document for updating. + * @param chatRoomId - The ID of the chatRoom document to read. + */ +export const updateChatRoomDocumentReference = ({ + chatRoomId +}: { + chatRoomId: string +}): DocumentReference => + updateChatRoomCollectionReference.doc(chatRoomId) + +/** + * Provides a reference to the chatRooms collection for deleting. + */ +export const deleteChatRoomCollectionReference = db + .collection(`chatRooms`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteChatRoom` + ) + }, + toFirestore: (): DocumentData => { + throw new Error(`toFirestore is not implemented for DeleteChatRoom`) + } + }) + +/** + * Provides a reference to a chatRoom document for deleting. + * @param chatRoomId - The ID of the chatRoom document to read. + */ +export const deleteChatRoomDocumentReference = ({ + chatRoomId +}: { + chatRoomId: string +}): DocumentReference => + deleteChatRoomCollectionReference.doc(chatRoomId) + +/** + * Manages queries against the chatRooms collection. + */ +export class ChatRoomQuery { + /** + * Fetches chatRoom documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadChatRoom, rhs: ReadChatRoom) => number + }): Promise { + let query: Query = readChatRoomCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map((qds: QueryDocumentSnapshot) => + qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific chatRoom document. + * @param chatRoomId - The ID of the chatRoom document to fetch. + */ + async fetchDocument({ + chatRoomId + }: { + chatRoomId: string + }): Promise { + const ds = await readChatRoomDocumentReference({ + chatRoomId + }).get() + return ds.data() + } + + /** + * Adds a chatRoom document. + * @param createChatRoom - The chatRoom details to add. + */ + async add({ + createChatRoom + }: { + createChatRoom: CreateChatRoom + }): Promise> { + return createChatRoomCollectionReference.add(createChatRoom) + } + + /** + * Sets a chatRoom document. + * @param chatRoomId - The ID of the chatRoom document to set. + * @param createChatRoom - The chatRoom details to set. + * @param options - Options for the set operation. + */ + async set({ + chatRoomId, + createChatRoom, + options + }: { + chatRoomId: string + createChatRoom: CreateChatRoom + options?: SetOptions + }): Promise { + if (options == undefined) { + return createChatRoomDocumentReference({ + chatRoomId + }).set(createChatRoom) + } else { + return createChatRoomDocumentReference({ + chatRoomId + }).set(createChatRoom, options) + } + } + + /** + * Updates a specific chatRoom document. + * @param chatRoomId - The ID of the chatRoom document to update. + * @param updateChatRoom - The details for updating the chatRoom. + */ + async update({ + chatRoomId, + updateChatRoom + }: { + chatRoomId: string + updateChatRoom: UpdateChatRoom + }): Promise { + return updateChatRoomDocumentReference({ + chatRoomId + }).update(updateChatRoom.toJson()) + } + + /** + * Deletes a specific chatRoom document. + * @param chatRoomId - The ID of the chatRoom document to delete. + */ + async delete({ chatRoomId }: { chatRoomId: string }): Promise { + return deleteChatRoomDocumentReference({ + chatRoomId + }).delete() + } +} diff --git a/functions/src/firestore-documents/forceUpdateConfig.flutterfireGen.ts b/functions/src/firestore-documents/forceUpdateConfig.flutterfireGen.ts new file mode 100644 index 00000000..1e4a832c --- /dev/null +++ b/functions/src/firestore-documents/forceUpdateConfig.flutterfireGen.ts @@ -0,0 +1,442 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadForceUpdateConfig { + constructor({ + forceUpdateConfigId, + path, + iOSLatestVersion, + iOSMinRequiredVersion, + iOSForceUpdate, + androidLatestVersion, + androidMinRequiredVersion, + androidForceUpdate + }: { + forceUpdateConfigId: string + path: string + iOSLatestVersion: string + iOSMinRequiredVersion: string + iOSForceUpdate: boolean + androidLatestVersion: string + androidMinRequiredVersion: string + androidForceUpdate: boolean + }) { + this.forceUpdateConfigId = forceUpdateConfigId + this.path = path + this.iOSLatestVersion = iOSLatestVersion + this.iOSMinRequiredVersion = iOSMinRequiredVersion + this.iOSForceUpdate = iOSForceUpdate + this.androidLatestVersion = androidLatestVersion + this.androidMinRequiredVersion = androidMinRequiredVersion + this.androidForceUpdate = androidForceUpdate + } + + readonly forceUpdateConfigId: string + + readonly path: string + + readonly iOSLatestVersion: string + + readonly iOSMinRequiredVersion: string + + readonly iOSForceUpdate: boolean + + readonly androidLatestVersion: string + + readonly androidMinRequiredVersion: string + + readonly androidForceUpdate: boolean + + private static fromJson( + json: Record + ): ReadForceUpdateConfig { + return new ReadForceUpdateConfig({ + forceUpdateConfigId: json[`forceUpdateConfigId`] as string, + path: json[`path`] as string, + iOSLatestVersion: json[`iOSLatestVersion`] as string, + iOSMinRequiredVersion: json[`iOSMinRequiredVersion`] as string, + iOSForceUpdate: + (json[`iOSForceUpdate`] as boolean | undefined) ?? false, + androidLatestVersion: json[`androidLatestVersion`] as string, + androidMinRequiredVersion: json[ + `androidMinRequiredVersion` + ] as string, + androidForceUpdate: + (json[`androidForceUpdate`] as boolean | undefined) ?? false + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadForceUpdateConfig { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadForceUpdateConfig.fromJson({ + ...cleanedData, + forceUpdateConfigId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateForceUpdateConfig { + constructor({ + iOSLatestVersion, + iOSMinRequiredVersion, + iOSForceUpdate, + androidLatestVersion, + androidMinRequiredVersion, + androidForceUpdate + }: { + iOSLatestVersion: string + iOSMinRequiredVersion: string + iOSForceUpdate: boolean + androidLatestVersion: string + androidMinRequiredVersion: string + androidForceUpdate: boolean + }) { + this.iOSLatestVersion = iOSLatestVersion + this.iOSMinRequiredVersion = iOSMinRequiredVersion + this.iOSForceUpdate = iOSForceUpdate + this.androidLatestVersion = androidLatestVersion + this.androidMinRequiredVersion = androidMinRequiredVersion + this.androidForceUpdate = androidForceUpdate + } + + readonly iOSLatestVersion: string + + readonly iOSMinRequiredVersion: string + + readonly iOSForceUpdate: boolean + + readonly androidLatestVersion: string + + readonly androidMinRequiredVersion: string + + readonly androidForceUpdate: boolean + + toJson(): Record { + return { + iOSLatestVersion: this.iOSLatestVersion, + iOSMinRequiredVersion: this.iOSMinRequiredVersion, + iOSForceUpdate: this.iOSForceUpdate, + androidLatestVersion: this.androidLatestVersion, + androidMinRequiredVersion: this.androidMinRequiredVersion, + androidForceUpdate: this.androidForceUpdate + } + } +} + +export class UpdateForceUpdateConfig { + constructor({ + iOSLatestVersion, + iOSMinRequiredVersion, + iOSForceUpdate, + androidLatestVersion, + androidMinRequiredVersion, + androidForceUpdate + }: { + iOSLatestVersion?: string + iOSMinRequiredVersion?: string + iOSForceUpdate?: boolean + androidLatestVersion?: string + androidMinRequiredVersion?: string + androidForceUpdate?: boolean + }) { + this.iOSLatestVersion = iOSLatestVersion + this.iOSMinRequiredVersion = iOSMinRequiredVersion + this.iOSForceUpdate = iOSForceUpdate + this.androidLatestVersion = androidLatestVersion + this.androidMinRequiredVersion = androidMinRequiredVersion + this.androidForceUpdate = androidForceUpdate + } + + readonly iOSLatestVersion?: string + + readonly iOSMinRequiredVersion?: string + + readonly iOSForceUpdate?: boolean + + readonly androidLatestVersion?: string + + readonly androidMinRequiredVersion?: string + + readonly androidForceUpdate?: boolean + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.iOSLatestVersion != undefined) { + json[`iOSLatestVersion`] = this.iOSLatestVersion + } + if (this.iOSMinRequiredVersion != undefined) { + json[`iOSMinRequiredVersion`] = this.iOSMinRequiredVersion + } + if (this.iOSForceUpdate != undefined) { + json[`iOSForceUpdate`] = this.iOSForceUpdate + } + if (this.androidLatestVersion != undefined) { + json[`androidLatestVersion`] = this.androidLatestVersion + } + if (this.androidMinRequiredVersion != undefined) { + json[`androidMinRequiredVersion`] = this.androidMinRequiredVersion + } + if (this.androidForceUpdate != undefined) { + json[`androidForceUpdate`] = this.androidForceUpdate + } + + return json + } +} + +export class DeleteForceUpdateConfig {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the configurations collection for reading. + */ +export const readForceUpdateConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadForceUpdateConfig => { + return ReadForceUpdateConfig.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadForceUpdateConfig` + ) + } + }) + +/** + * Provides a reference to a forceUpdateConfig document for reading. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to read. + */ +export const readForceUpdateConfigDocumentReference = ({ + forceUpdateConfigId +}: { + forceUpdateConfigId: string +}): DocumentReference => + readForceUpdateConfigCollectionReference.doc(forceUpdateConfigId) + +/** + * Provides a reference to the configurations collection for creating. + */ +export const createForceUpdateConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateForceUpdateConfig` + ) + }, + toFirestore: (obj: CreateForceUpdateConfig): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a forceUpdateConfig document for creating. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to read. + */ +export const createForceUpdateConfigDocumentReference = ({ + forceUpdateConfigId +}: { + forceUpdateConfigId: string +}): DocumentReference => + createForceUpdateConfigCollectionReference.doc(forceUpdateConfigId) + +/** + * Provides a reference to the configurations collection for updating. + */ +export const updateForceUpdateConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateForceUpdateConfig` + ) + }, + toFirestore: (obj: UpdateForceUpdateConfig): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a forceUpdateConfig document for updating. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to read. + */ +export const updateForceUpdateConfigDocumentReference = ({ + forceUpdateConfigId +}: { + forceUpdateConfigId: string +}): DocumentReference => + updateForceUpdateConfigCollectionReference.doc(forceUpdateConfigId) + +/** + * Provides a reference to the configurations collection for deleting. + */ +export const deleteForceUpdateConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteForceUpdateConfig` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteForceUpdateConfig` + ) + } + }) + +/** + * Provides a reference to a forceUpdateConfig document for deleting. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to read. + */ +export const deleteForceUpdateConfigDocumentReference = ({ + forceUpdateConfigId +}: { + forceUpdateConfigId: string +}): DocumentReference => + deleteForceUpdateConfigCollectionReference.doc(forceUpdateConfigId) + +/** + * Manages queries against the configurations collection. + */ +export class ForceUpdateConfigQuery { + /** + * Fetches forceUpdateConfig documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: ( + query: Query + ) => Query + compare?: ( + lhs: ReadForceUpdateConfig, + rhs: ReadForceUpdateConfig + ) => number + }): Promise { + let query: Query = + readForceUpdateConfigCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific forceUpdateConfig document. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to fetch. + */ + async fetchDocument({ + forceUpdateConfigId + }: { + forceUpdateConfigId: string + }): Promise { + const ds = await readForceUpdateConfigDocumentReference({ + forceUpdateConfigId + }).get() + return ds.data() + } + + /** + * Adds a forceUpdateConfig document. + * @param createForceUpdateConfig - The forceUpdateConfig details to add. + */ + async add({ + createForceUpdateConfig + }: { + createForceUpdateConfig: CreateForceUpdateConfig + }): Promise> { + return createForceUpdateConfigCollectionReference.add( + createForceUpdateConfig + ) + } + + /** + * Sets a forceUpdateConfig document. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to set. + * @param createForceUpdateConfig - The forceUpdateConfig details to set. + * @param options - Options for the set operation. + */ + async set({ + forceUpdateConfigId, + createForceUpdateConfig, + options + }: { + forceUpdateConfigId: string + createForceUpdateConfig: CreateForceUpdateConfig + options?: SetOptions + }): Promise { + if (options == undefined) { + return createForceUpdateConfigDocumentReference({ + forceUpdateConfigId + }).set(createForceUpdateConfig) + } else { + return createForceUpdateConfigDocumentReference({ + forceUpdateConfigId + }).set(createForceUpdateConfig, options) + } + } + + /** + * Updates a specific forceUpdateConfig document. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to update. + * @param updateForceUpdateConfig - The details for updating the forceUpdateConfig. + */ + async update({ + forceUpdateConfigId, + updateForceUpdateConfig + }: { + forceUpdateConfigId: string + updateForceUpdateConfig: UpdateForceUpdateConfig + }): Promise { + return updateForceUpdateConfigDocumentReference({ + forceUpdateConfigId + }).update(updateForceUpdateConfig.toJson()) + } + + /** + * Deletes a specific forceUpdateConfig document. + * @param forceUpdateConfigId - The ID of the forceUpdateConfig document to delete. + */ + async delete({ + forceUpdateConfigId + }: { + forceUpdateConfigId: string + }): Promise { + return deleteForceUpdateConfigDocumentReference({ + forceUpdateConfigId + }).delete() + } +} diff --git a/functions/src/firestore-documents/host.flutterfireGen.ts b/functions/src/firestore-documents/host.flutterfireGen.ts new file mode 100644 index 00000000..1786f62d --- /dev/null +++ b/functions/src/firestore-documents/host.flutterfireGen.ts @@ -0,0 +1,444 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export type HostType = `farmer` | `fisherman` | `hunter` | `other` + +export class ReadHost { + constructor({ + hostId, + path, + imageUrl, + displayName, + introduction, + hostTypes, + urls, + createdAt, + updatedAt + }: { + hostId: string + path: string + imageUrl: string + displayName: string + introduction: string + hostTypes: Set + urls: string[] + createdAt?: Date + updatedAt?: Date + }) { + this.hostId = hostId + this.path = path + this.imageUrl = imageUrl + this.displayName = displayName + this.introduction = introduction + this.hostTypes = hostTypes + this.urls = urls + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly hostId: string + + readonly path: string + + readonly imageUrl: string + + readonly displayName: string + + readonly introduction: string + + readonly hostTypes: Set + + readonly urls: string[] + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static hostTypesConverterFromJson( + hostTypes: unknown[] | undefined + ): Set { + return new Set((hostTypes ?? []).map((e) => e as HostType)) + } + + private static fromJson(json: Record): ReadHost { + return new ReadHost({ + hostId: json[`hostId`] as string, + path: json[`path`] as string, + imageUrl: (json[`imageUrl`] as string | undefined) ?? ``, + displayName: (json[`displayName`] as string | undefined) ?? ``, + introduction: (json[`introduction`] as string | undefined) ?? ``, + hostTypes: + json[`hostTypes`] == undefined + ? new Set() + : ReadHost.hostTypesConverterFromJson( + json[`hostTypes`] as unknown[] + ), + urls: + (json[`urls`] as unknown[] | undefined)?.map( + (e) => e as string + ) ?? [], + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadHost { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadHost.fromJson({ + ...cleanedData, + hostId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateHost { + constructor({ + imageUrl, + displayName, + introduction, + hostTypes, + urls + }: { + imageUrl: string + displayName: string + introduction: string + hostTypes: Set + urls: string[] + }) { + this.imageUrl = imageUrl + this.displayName = displayName + this.introduction = introduction + this.hostTypes = hostTypes + this.urls = urls + } + + readonly imageUrl: string + + readonly displayName: string + + readonly introduction: string + + readonly hostTypes: Set + + readonly urls: string[] + + private static hostTypesConverterToJson( + hostTypes: Set + ): string[] { + return [...hostTypes] + } + + toJson(): Record { + return { + imageUrl: this.imageUrl, + displayName: this.displayName, + introduction: this.introduction, + hostTypes: CreateHost.hostTypesConverterToJson(this.hostTypes), + urls: this.urls, + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateHost { + constructor({ + imageUrl, + displayName, + introduction, + hostTypes, + urls, + createdAt + }: { + imageUrl?: string + displayName?: string + introduction?: string + hostTypes?: Set + urls?: string[] + createdAt?: Date + }) { + this.imageUrl = imageUrl + this.displayName = displayName + this.introduction = introduction + this.hostTypes = hostTypes + this.urls = urls + this.createdAt = createdAt + } + + readonly imageUrl?: string + + readonly displayName?: string + + readonly introduction?: string + + readonly hostTypes?: Set + + readonly urls?: string[] + + readonly createdAt?: Date + + private static hostTypesConverterToJson( + hostTypes: Set + ): string[] { + return [...hostTypes] + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.imageUrl != undefined) { + json[`imageUrl`] = this.imageUrl + } + if (this.displayName != undefined) { + json[`displayName`] = this.displayName + } + if (this.introduction != undefined) { + json[`introduction`] = this.introduction + } + if (this.hostTypes != undefined) { + json[`hostTypes`] = UpdateHost.hostTypesConverterToJson( + this.hostTypes + ) + } + if (this.urls != undefined) { + json[`urls`] = this.urls + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteHost {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the hosts collection for reading. + */ +export const readHostCollectionReference = db + .collection(`hosts`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadHost => { + return ReadHost.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error(`toFirestore is not implemented for ReadHost`) + } + }) + +/** + * Provides a reference to a host document for reading. + * @param hostId - The ID of the host document to read. + */ +export const readHostDocumentReference = ({ + hostId +}: { + hostId: string +}): DocumentReference => readHostCollectionReference.doc(hostId) + +/** + * Provides a reference to the hosts collection for creating. + */ +export const createHostCollectionReference = db + .collection(`hosts`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for CreateHost`) + }, + toFirestore: (obj: CreateHost): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a host document for creating. + * @param hostId - The ID of the host document to read. + */ +export const createHostDocumentReference = ({ + hostId +}: { + hostId: string +}): DocumentReference => createHostCollectionReference.doc(hostId) + +/** + * Provides a reference to the hosts collection for updating. + */ +export const updateHostCollectionReference = db + .collection(`hosts`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for UpdateHost`) + }, + toFirestore: (obj: UpdateHost): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a host document for updating. + * @param hostId - The ID of the host document to read. + */ +export const updateHostDocumentReference = ({ + hostId +}: { + hostId: string +}): DocumentReference => updateHostCollectionReference.doc(hostId) + +/** + * Provides a reference to the hosts collection for deleting. + */ +export const deleteHostCollectionReference = db + .collection(`hosts`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for DeleteHost`) + }, + toFirestore: (): DocumentData => { + throw new Error(`toFirestore is not implemented for DeleteHost`) + } + }) + +/** + * Provides a reference to a host document for deleting. + * @param hostId - The ID of the host document to read. + */ +export const deleteHostDocumentReference = ({ + hostId +}: { + hostId: string +}): DocumentReference => deleteHostCollectionReference.doc(hostId) + +/** + * Manages queries against the hosts collection. + */ +export class HostQuery { + /** + * Fetches host documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadHost, rhs: ReadHost) => number + }): Promise { + let query: Query = readHostCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map((qds: QueryDocumentSnapshot) => + qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific host document. + * @param hostId - The ID of the host document to fetch. + */ + async fetchDocument({ + hostId + }: { + hostId: string + }): Promise { + const ds = await readHostDocumentReference({ + hostId + }).get() + return ds.data() + } + + /** + * Adds a host document. + * @param createHost - The host details to add. + */ + async add({ + createHost + }: { + createHost: CreateHost + }): Promise> { + return createHostCollectionReference.add(createHost) + } + + /** + * Sets a host document. + * @param hostId - The ID of the host document to set. + * @param createHost - The host details to set. + * @param options - Options for the set operation. + */ + async set({ + hostId, + createHost, + options + }: { + hostId: string + createHost: CreateHost + options?: SetOptions + }): Promise { + if (options == undefined) { + return createHostDocumentReference({ + hostId + }).set(createHost) + } else { + return createHostDocumentReference({ + hostId + }).set(createHost, options) + } + } + + /** + * Updates a specific host document. + * @param hostId - The ID of the host document to update. + * @param updateHost - The details for updating the host. + */ + async update({ + hostId, + updateHost + }: { + hostId: string + updateHost: UpdateHost + }): Promise { + return updateHostDocumentReference({ + hostId + }).update(updateHost.toJson()) + } + + /** + * Deletes a specific host document. + * @param hostId - The ID of the host document to delete. + */ + async delete({ hostId }: { hostId: string }): Promise { + return deleteHostDocumentReference({ + hostId + }).delete() + } +} diff --git a/functions/src/firestore-documents/hostLocation.flutterfireGen.ts b/functions/src/firestore-documents/hostLocation.flutterfireGen.ts new file mode 100644 index 00000000..8d43dfc2 --- /dev/null +++ b/functions/src/firestore-documents/hostLocation.flutterfireGen.ts @@ -0,0 +1,434 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + GeoPoint, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export class Geo { + constructor({ + geohash, + geopoint + }: { + geohash: string + geopoint: GeoPoint + }) { + this.geohash = geohash + this.geopoint = geopoint + } + + readonly geohash: string + + readonly geopoint: GeoPoint +} + +export class ReadHostLocation { + constructor({ + hostLocationId, + path, + hostId, + address, + geo, + createdAt, + updatedAt + }: { + hostLocationId: string + path: string + hostId: string + address: string + geo: Geo + createdAt?: Date + updatedAt?: Date + }) { + this.hostLocationId = hostLocationId + this.path = path + this.hostId = hostId + this.address = address + this.geo = geo + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly hostLocationId: string + + readonly path: string + + readonly hostId: string + + readonly address: string + + readonly geo: Geo + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static geoConverterFromJson(json: Record): Geo { + const geohash = json[`geohash`] as string + const geopoint = json[`geopoint`] as GeoPoint + return new Geo({ geohash, geopoint }) + } + + private static fromJson(json: Record): ReadHostLocation { + return new ReadHostLocation({ + hostLocationId: json[`hostLocationId`] as string, + path: json[`path`] as string, + hostId: json[`hostId`] as string, + address: (json[`address`] as string | undefined) ?? ``, + geo: ReadHostLocation.geoConverterFromJson( + json[`geo`] as Record + ), + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadHostLocation { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadHostLocation.fromJson({ + ...cleanedData, + hostLocationId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateHostLocation { + constructor({ + hostId, + address, + geo + }: { + hostId: string + address: string + geo: Geo + }) { + this.hostId = hostId + this.address = address + this.geo = geo + } + + readonly hostId: string + + readonly address: string + + readonly geo: Geo + + private static geoConverterToJson(geo: Geo): Record { + return { + geohash: geo.geohash, + geopoint: geo.geopoint + } + } + + toJson(): Record { + return { + hostId: this.hostId, + address: this.address, + geo: CreateHostLocation.geoConverterToJson(this.geo), + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateHostLocation { + constructor({ + hostId, + address, + geo, + createdAt + }: { + hostId?: string + address?: string + geo?: Geo + createdAt?: Date + }) { + this.hostId = hostId + this.address = address + this.geo = geo + this.createdAt = createdAt + } + + readonly hostId?: string + + readonly address?: string + + readonly geo?: Geo + + readonly createdAt?: Date + + private static geoConverterToJson(geo: Geo): Record { + return { + geohash: geo.geohash, + geopoint: geo.geopoint + } + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.hostId != undefined) { + json[`hostId`] = this.hostId + } + if (this.address != undefined) { + json[`address`] = this.address + } + if (this.geo != undefined) { + json[`geo`] = UpdateHostLocation.geoConverterToJson(this.geo) + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteHostLocation {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the hostLocations collection for reading. + */ +export const readHostLocationCollectionReference = db + .collection(`hostLocations`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadHostLocation => { + return ReadHostLocation.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadHostLocation` + ) + } + }) + +/** + * Provides a reference to a hostLocation document for reading. + * @param hostLocationId - The ID of the hostLocation document to read. + */ +export const readHostLocationDocumentReference = ({ + hostLocationId +}: { + hostLocationId: string +}): DocumentReference => + readHostLocationCollectionReference.doc(hostLocationId) + +/** + * Provides a reference to the hostLocations collection for creating. + */ +export const createHostLocationCollectionReference = db + .collection(`hostLocations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateHostLocation` + ) + }, + toFirestore: (obj: CreateHostLocation): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a hostLocation document for creating. + * @param hostLocationId - The ID of the hostLocation document to read. + */ +export const createHostLocationDocumentReference = ({ + hostLocationId +}: { + hostLocationId: string +}): DocumentReference => + createHostLocationCollectionReference.doc(hostLocationId) + +/** + * Provides a reference to the hostLocations collection for updating. + */ +export const updateHostLocationCollectionReference = db + .collection(`hostLocations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateHostLocation` + ) + }, + toFirestore: (obj: UpdateHostLocation): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a hostLocation document for updating. + * @param hostLocationId - The ID of the hostLocation document to read. + */ +export const updateHostLocationDocumentReference = ({ + hostLocationId +}: { + hostLocationId: string +}): DocumentReference => + updateHostLocationCollectionReference.doc(hostLocationId) + +/** + * Provides a reference to the hostLocations collection for deleting. + */ +export const deleteHostLocationCollectionReference = db + .collection(`hostLocations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteHostLocation` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteHostLocation` + ) + } + }) + +/** + * Provides a reference to a hostLocation document for deleting. + * @param hostLocationId - The ID of the hostLocation document to read. + */ +export const deleteHostLocationDocumentReference = ({ + hostLocationId +}: { + hostLocationId: string +}): DocumentReference => + deleteHostLocationCollectionReference.doc(hostLocationId) + +/** + * Manages queries against the hostLocations collection. + */ +export class HostLocationQuery { + /** + * Fetches hostLocation documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: ( + query: Query + ) => Query + compare?: (lhs: ReadHostLocation, rhs: ReadHostLocation) => number + }): Promise { + let query: Query = readHostLocationCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific hostLocation document. + * @param hostLocationId - The ID of the hostLocation document to fetch. + */ + async fetchDocument({ + hostLocationId + }: { + hostLocationId: string + }): Promise { + const ds = await readHostLocationDocumentReference({ + hostLocationId + }).get() + return ds.data() + } + + /** + * Adds a hostLocation document. + * @param createHostLocation - The hostLocation details to add. + */ + async add({ + createHostLocation + }: { + createHostLocation: CreateHostLocation + }): Promise> { + return createHostLocationCollectionReference.add(createHostLocation) + } + + /** + * Sets a hostLocation document. + * @param hostLocationId - The ID of the hostLocation document to set. + * @param createHostLocation - The hostLocation details to set. + * @param options - Options for the set operation. + */ + async set({ + hostLocationId, + createHostLocation, + options + }: { + hostLocationId: string + createHostLocation: CreateHostLocation + options?: SetOptions + }): Promise { + if (options == undefined) { + return createHostLocationDocumentReference({ + hostLocationId + }).set(createHostLocation) + } else { + return createHostLocationDocumentReference({ + hostLocationId + }).set(createHostLocation, options) + } + } + + /** + * Updates a specific hostLocation document. + * @param hostLocationId - The ID of the hostLocation document to update. + * @param updateHostLocation - The details for updating the hostLocation. + */ + async update({ + hostLocationId, + updateHostLocation + }: { + hostLocationId: string + updateHostLocation: UpdateHostLocation + }): Promise { + return updateHostLocationDocumentReference({ + hostLocationId + }).update(updateHostLocation.toJson()) + } + + /** + * Deletes a specific hostLocation document. + * @param hostLocationId - The ID of the hostLocation document to delete. + */ + async delete({ + hostLocationId + }: { + hostLocationId: string + }): Promise { + return deleteHostLocationDocumentReference({ + hostLocationId + }).delete() + } +} diff --git a/functions/src/firestore-documents/inReviewConfig.flutterfireGen.ts b/functions/src/firestore-documents/inReviewConfig.flutterfireGen.ts new file mode 100644 index 00000000..3ddea2f8 --- /dev/null +++ b/functions/src/firestore-documents/inReviewConfig.flutterfireGen.ts @@ -0,0 +1,397 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadInReviewConfig { + constructor({ + inReviewConfigId, + path, + iOSInReviewVersion, + enableIOSInReviewMode, + androidInReviewVersion, + enableAndroidInReviewMode + }: { + inReviewConfigId: string + path: string + iOSInReviewVersion: string + enableIOSInReviewMode: boolean + androidInReviewVersion: string + enableAndroidInReviewMode: boolean + }) { + this.inReviewConfigId = inReviewConfigId + this.path = path + this.iOSInReviewVersion = iOSInReviewVersion + this.enableIOSInReviewMode = enableIOSInReviewMode + this.androidInReviewVersion = androidInReviewVersion + this.enableAndroidInReviewMode = enableAndroidInReviewMode + } + + readonly inReviewConfigId: string + + readonly path: string + + readonly iOSInReviewVersion: string + + readonly enableIOSInReviewMode: boolean + + readonly androidInReviewVersion: string + + readonly enableAndroidInReviewMode: boolean + + private static fromJson(json: Record): ReadInReviewConfig { + return new ReadInReviewConfig({ + inReviewConfigId: json[`inReviewConfigId`] as string, + path: json[`path`] as string, + iOSInReviewVersion: + (json[`iOSInReviewVersion`] as string | undefined) ?? `1.0.0`, + enableIOSInReviewMode: + (json[`enableIOSInReviewMode`] as boolean | undefined) ?? false, + androidInReviewVersion: + (json[`androidInReviewVersion`] as string | undefined) ?? + `1.0.0`, + enableAndroidInReviewMode: + (json[`enableAndroidInReviewMode`] as boolean | undefined) ?? + false + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadInReviewConfig { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadInReviewConfig.fromJson({ + ...cleanedData, + inReviewConfigId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateInReviewConfig { + constructor({ + iOSInReviewVersion, + enableIOSInReviewMode, + androidInReviewVersion, + enableAndroidInReviewMode + }: { + iOSInReviewVersion: string + enableIOSInReviewMode: boolean + androidInReviewVersion: string + enableAndroidInReviewMode: boolean + }) { + this.iOSInReviewVersion = iOSInReviewVersion + this.enableIOSInReviewMode = enableIOSInReviewMode + this.androidInReviewVersion = androidInReviewVersion + this.enableAndroidInReviewMode = enableAndroidInReviewMode + } + + readonly iOSInReviewVersion: string + + readonly enableIOSInReviewMode: boolean + + readonly androidInReviewVersion: string + + readonly enableAndroidInReviewMode: boolean + + toJson(): Record { + return { + iOSInReviewVersion: this.iOSInReviewVersion, + enableIOSInReviewMode: this.enableIOSInReviewMode, + androidInReviewVersion: this.androidInReviewVersion, + enableAndroidInReviewMode: this.enableAndroidInReviewMode + } + } +} + +export class UpdateInReviewConfig { + constructor({ + iOSInReviewVersion, + enableIOSInReviewMode, + androidInReviewVersion, + enableAndroidInReviewMode + }: { + iOSInReviewVersion?: string + enableIOSInReviewMode?: boolean + androidInReviewVersion?: string + enableAndroidInReviewMode?: boolean + }) { + this.iOSInReviewVersion = iOSInReviewVersion + this.enableIOSInReviewMode = enableIOSInReviewMode + this.androidInReviewVersion = androidInReviewVersion + this.enableAndroidInReviewMode = enableAndroidInReviewMode + } + + readonly iOSInReviewVersion?: string + + readonly enableIOSInReviewMode?: boolean + + readonly androidInReviewVersion?: string + + readonly enableAndroidInReviewMode?: boolean + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.iOSInReviewVersion != undefined) { + json[`iOSInReviewVersion`] = this.iOSInReviewVersion + } + if (this.enableIOSInReviewMode != undefined) { + json[`enableIOSInReviewMode`] = this.enableIOSInReviewMode + } + if (this.androidInReviewVersion != undefined) { + json[`androidInReviewVersion`] = this.androidInReviewVersion + } + if (this.enableAndroidInReviewMode != undefined) { + json[`enableAndroidInReviewMode`] = this.enableAndroidInReviewMode + } + + return json + } +} + +export class DeleteInReviewConfig {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the configurations collection for reading. + */ +export const readInReviewConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadInReviewConfig => { + return ReadInReviewConfig.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadInReviewConfig` + ) + } + }) + +/** + * Provides a reference to a inReviewConfig document for reading. + * @param inReviewConfigId - The ID of the inReviewConfig document to read. + */ +export const readInReviewConfigDocumentReference = ({ + inReviewConfigId +}: { + inReviewConfigId: string +}): DocumentReference => + readInReviewConfigCollectionReference.doc(inReviewConfigId) + +/** + * Provides a reference to the configurations collection for creating. + */ +export const createInReviewConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateInReviewConfig` + ) + }, + toFirestore: (obj: CreateInReviewConfig): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a inReviewConfig document for creating. + * @param inReviewConfigId - The ID of the inReviewConfig document to read. + */ +export const createInReviewConfigDocumentReference = ({ + inReviewConfigId +}: { + inReviewConfigId: string +}): DocumentReference => + createInReviewConfigCollectionReference.doc(inReviewConfigId) + +/** + * Provides a reference to the configurations collection for updating. + */ +export const updateInReviewConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateInReviewConfig` + ) + }, + toFirestore: (obj: UpdateInReviewConfig): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a inReviewConfig document for updating. + * @param inReviewConfigId - The ID of the inReviewConfig document to read. + */ +export const updateInReviewConfigDocumentReference = ({ + inReviewConfigId +}: { + inReviewConfigId: string +}): DocumentReference => + updateInReviewConfigCollectionReference.doc(inReviewConfigId) + +/** + * Provides a reference to the configurations collection for deleting. + */ +export const deleteInReviewConfigCollectionReference = db + .collection(`configurations`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteInReviewConfig` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteInReviewConfig` + ) + } + }) + +/** + * Provides a reference to a inReviewConfig document for deleting. + * @param inReviewConfigId - The ID of the inReviewConfig document to read. + */ +export const deleteInReviewConfigDocumentReference = ({ + inReviewConfigId +}: { + inReviewConfigId: string +}): DocumentReference => + deleteInReviewConfigCollectionReference.doc(inReviewConfigId) + +/** + * Manages queries against the configurations collection. + */ +export class InReviewConfigQuery { + /** + * Fetches inReviewConfig documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: ( + query: Query + ) => Query + compare?: (lhs: ReadInReviewConfig, rhs: ReadInReviewConfig) => number + }): Promise { + let query: Query = + readInReviewConfigCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific inReviewConfig document. + * @param inReviewConfigId - The ID of the inReviewConfig document to fetch. + */ + async fetchDocument({ + inReviewConfigId + }: { + inReviewConfigId: string + }): Promise { + const ds = await readInReviewConfigDocumentReference({ + inReviewConfigId + }).get() + return ds.data() + } + + /** + * Adds a inReviewConfig document. + * @param createInReviewConfig - The inReviewConfig details to add. + */ + async add({ + createInReviewConfig + }: { + createInReviewConfig: CreateInReviewConfig + }): Promise> { + return createInReviewConfigCollectionReference.add(createInReviewConfig) + } + + /** + * Sets a inReviewConfig document. + * @param inReviewConfigId - The ID of the inReviewConfig document to set. + * @param createInReviewConfig - The inReviewConfig details to set. + * @param options - Options for the set operation. + */ + async set({ + inReviewConfigId, + createInReviewConfig, + options + }: { + inReviewConfigId: string + createInReviewConfig: CreateInReviewConfig + options?: SetOptions + }): Promise { + if (options == undefined) { + return createInReviewConfigDocumentReference({ + inReviewConfigId + }).set(createInReviewConfig) + } else { + return createInReviewConfigDocumentReference({ + inReviewConfigId + }).set(createInReviewConfig, options) + } + } + + /** + * Updates a specific inReviewConfig document. + * @param inReviewConfigId - The ID of the inReviewConfig document to update. + * @param updateInReviewConfig - The details for updating the inReviewConfig. + */ + async update({ + inReviewConfigId, + updateInReviewConfig + }: { + inReviewConfigId: string + updateInReviewConfig: UpdateInReviewConfig + }): Promise { + return updateInReviewConfigDocumentReference({ + inReviewConfigId + }).update(updateInReviewConfig.toJson()) + } + + /** + * Deletes a specific inReviewConfig document. + * @param inReviewConfigId - The ID of the inReviewConfig document to delete. + */ + async delete({ + inReviewConfigId + }: { + inReviewConfigId: string + }): Promise { + return deleteInReviewConfigDocumentReference({ + inReviewConfigId + }).delete() + } +} diff --git a/functions/src/firestore-documents/job.flutterfireGen.ts b/functions/src/firestore-documents/job.flutterfireGen.ts new file mode 100644 index 00000000..dcdd5dc9 --- /dev/null +++ b/functions/src/firestore-documents/job.flutterfireGen.ts @@ -0,0 +1,547 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export type AccessType = + | `trainAvailable` + | `busAvailable` + | `parkingAvailable` + | `walkableFromNearest` + | `shuttleServiceAvailable` + +export class ReadJob { + constructor({ + jobId, + path, + hostId, + imageUrl, + title, + place, + content, + belongings, + reward, + accessDescription, + accessTypes, + comment, + createdAt, + updatedAt + }: { + jobId: string + path: string + hostId: string + imageUrl: string + title: string + place: string + content: string + belongings: string + reward: string + accessDescription: string + accessTypes: Set + comment: string + createdAt?: Date + updatedAt?: Date + }) { + this.jobId = jobId + this.path = path + this.hostId = hostId + this.imageUrl = imageUrl + this.title = title + this.place = place + this.content = content + this.belongings = belongings + this.reward = reward + this.accessDescription = accessDescription + this.accessTypes = accessTypes + this.comment = comment + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly jobId: string + + readonly path: string + + readonly hostId: string + + readonly imageUrl: string + + readonly title: string + + readonly place: string + + readonly content: string + + readonly belongings: string + + readonly reward: string + + readonly accessDescription: string + + readonly accessTypes: Set + + readonly comment: string + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static accessTypesConverterFromJson( + accessTypes: unknown[] | undefined + ): Set { + return new Set((accessTypes ?? []).map((e) => e as AccessType)) + } + + private static fromJson(json: Record): ReadJob { + return new ReadJob({ + jobId: json[`jobId`] as string, + path: json[`path`] as string, + hostId: json[`hostId`] as string, + imageUrl: (json[`imageUrl`] as string | undefined) ?? ``, + title: (json[`title`] as string | undefined) ?? ``, + place: (json[`place`] as string | undefined) ?? ``, + content: (json[`content`] as string | undefined) ?? ``, + belongings: (json[`belongings`] as string | undefined) ?? ``, + reward: (json[`reward`] as string | undefined) ?? ``, + accessDescription: + (json[`accessDescription`] as string | undefined) ?? ``, + accessTypes: + json[`accessTypes`] == undefined + ? new Set() + : ReadJob.accessTypesConverterFromJson( + json[`accessTypes`] as unknown[] + ), + comment: (json[`comment`] as string | undefined) ?? ``, + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadJob { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadJob.fromJson({ + ...cleanedData, + jobId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateJob { + constructor({ + hostId, + imageUrl, + title, + place, + content, + belongings, + reward, + accessDescription, + accessTypes, + comment + }: { + hostId: string + imageUrl: string + title: string + place: string + content: string + belongings: string + reward: string + accessDescription: string + accessTypes: Set + comment: string + }) { + this.hostId = hostId + this.imageUrl = imageUrl + this.title = title + this.place = place + this.content = content + this.belongings = belongings + this.reward = reward + this.accessDescription = accessDescription + this.accessTypes = accessTypes + this.comment = comment + } + + readonly hostId: string + + readonly imageUrl: string + + readonly title: string + + readonly place: string + + readonly content: string + + readonly belongings: string + + readonly reward: string + + readonly accessDescription: string + + readonly accessTypes: Set + + readonly comment: string + + private static accessTypesConverterToJson( + accessTypes: Set + ): string[] { + return [...accessTypes] + } + + toJson(): Record { + return { + hostId: this.hostId, + imageUrl: this.imageUrl, + title: this.title, + place: this.place, + content: this.content, + belongings: this.belongings, + reward: this.reward, + accessDescription: this.accessDescription, + accessTypes: CreateJob.accessTypesConverterToJson(this.accessTypes), + comment: this.comment, + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateJob { + constructor({ + hostId, + imageUrl, + title, + place, + content, + belongings, + reward, + accessDescription, + accessTypes, + comment, + createdAt + }: { + hostId?: string + imageUrl?: string + title?: string + place?: string + content?: string + belongings?: string + reward?: string + accessDescription?: string + accessTypes?: Set + comment?: string + createdAt?: Date + }) { + this.hostId = hostId + this.imageUrl = imageUrl + this.title = title + this.place = place + this.content = content + this.belongings = belongings + this.reward = reward + this.accessDescription = accessDescription + this.accessTypes = accessTypes + this.comment = comment + this.createdAt = createdAt + } + + readonly hostId?: string + + readonly imageUrl?: string + + readonly title?: string + + readonly place?: string + + readonly content?: string + + readonly belongings?: string + + readonly reward?: string + + readonly accessDescription?: string + + readonly accessTypes?: Set + + readonly comment?: string + + readonly createdAt?: Date + + private static accessTypesConverterToJson( + accessTypes: Set + ): string[] { + return [...accessTypes] + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.hostId != undefined) { + json[`hostId`] = this.hostId + } + if (this.imageUrl != undefined) { + json[`imageUrl`] = this.imageUrl + } + if (this.title != undefined) { + json[`title`] = this.title + } + if (this.place != undefined) { + json[`place`] = this.place + } + if (this.content != undefined) { + json[`content`] = this.content + } + if (this.belongings != undefined) { + json[`belongings`] = this.belongings + } + if (this.reward != undefined) { + json[`reward`] = this.reward + } + if (this.accessDescription != undefined) { + json[`accessDescription`] = this.accessDescription + } + if (this.accessTypes != undefined) { + json[`accessTypes`] = UpdateJob.accessTypesConverterToJson( + this.accessTypes + ) + } + if (this.comment != undefined) { + json[`comment`] = this.comment + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteJob {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the jobs collection for reading. + */ +export const readJobCollectionReference = db + .collection(`jobs`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadJob => { + return ReadJob.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error(`toFirestore is not implemented for ReadJob`) + } + }) + +/** + * Provides a reference to a job document for reading. + * @param jobId - The ID of the job document to read. + */ +export const readJobDocumentReference = ({ + jobId +}: { + jobId: string +}): DocumentReference => readJobCollectionReference.doc(jobId) + +/** + * Provides a reference to the jobs collection for creating. + */ +export const createJobCollectionReference = db + .collection(`jobs`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for CreateJob`) + }, + toFirestore: (obj: CreateJob): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a job document for creating. + * @param jobId - The ID of the job document to read. + */ +export const createJobDocumentReference = ({ + jobId +}: { + jobId: string +}): DocumentReference => createJobCollectionReference.doc(jobId) + +/** + * Provides a reference to the jobs collection for updating. + */ +export const updateJobCollectionReference = db + .collection(`jobs`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for UpdateJob`) + }, + toFirestore: (obj: UpdateJob): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a job document for updating. + * @param jobId - The ID of the job document to read. + */ +export const updateJobDocumentReference = ({ + jobId +}: { + jobId: string +}): DocumentReference => updateJobCollectionReference.doc(jobId) + +/** + * Provides a reference to the jobs collection for deleting. + */ +export const deleteJobCollectionReference = db + .collection(`jobs`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for DeleteJob`) + }, + toFirestore: (): DocumentData => { + throw new Error(`toFirestore is not implemented for DeleteJob`) + } + }) + +/** + * Provides a reference to a job document for deleting. + * @param jobId - The ID of the job document to read. + */ +export const deleteJobDocumentReference = ({ + jobId +}: { + jobId: string +}): DocumentReference => deleteJobCollectionReference.doc(jobId) + +/** + * Manages queries against the jobs collection. + */ +export class JobQuery { + /** + * Fetches job documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadJob, rhs: ReadJob) => number + }): Promise { + let query: Query = readJobCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map((qds: QueryDocumentSnapshot) => + qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific job document. + * @param jobId - The ID of the job document to fetch. + */ + async fetchDocument({ + jobId + }: { + jobId: string + }): Promise { + const ds = await readJobDocumentReference({ + jobId + }).get() + return ds.data() + } + + /** + * Adds a job document. + * @param createJob - The job details to add. + */ + async add({ + createJob + }: { + createJob: CreateJob + }): Promise> { + return createJobCollectionReference.add(createJob) + } + + /** + * Sets a job document. + * @param jobId - The ID of the job document to set. + * @param createJob - The job details to set. + * @param options - Options for the set operation. + */ + async set({ + jobId, + createJob, + options + }: { + jobId: string + createJob: CreateJob + options?: SetOptions + }): Promise { + if (options == undefined) { + return createJobDocumentReference({ + jobId + }).set(createJob) + } else { + return createJobDocumentReference({ + jobId + }).set(createJob, options) + } + } + + /** + * Updates a specific job document. + * @param jobId - The ID of the job document to update. + * @param updateJob - The details for updating the job. + */ + async update({ + jobId, + updateJob + }: { + jobId: string + updateJob: UpdateJob + }): Promise { + return updateJobDocumentReference({ + jobId + }).update(updateJob.toJson()) + } + + /** + * Deletes a specific job document. + * @param jobId - The ID of the job document to delete. + */ + async delete({ jobId }: { jobId: string }): Promise { + return deleteJobDocumentReference({ + jobId + }).delete() + } +} diff --git a/functions/src/firestore-documents/readStatus.flutterfireGen.ts b/functions/src/firestore-documents/readStatus.flutterfireGen.ts new file mode 100644 index 00000000..dafd1972 --- /dev/null +++ b/functions/src/firestore-documents/readStatus.flutterfireGen.ts @@ -0,0 +1,381 @@ +import * as admin from 'firebase-admin' +import { + CollectionReference, + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadReadStatus { + constructor({ + readStatusId, + path, + lastReadAt + }: { + readStatusId: string + path: string + lastReadAt?: Date + }) { + this.readStatusId = readStatusId + this.path = path + this.lastReadAt = lastReadAt + } + + readonly readStatusId: string + + readonly path: string + + readonly lastReadAt?: Date + + private static fromJson(json: Record): ReadReadStatus { + return new ReadReadStatus({ + readStatusId: json[`readStatusId`] as string, + path: json[`path`] as string, + lastReadAt: (json[`lastReadAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadReadStatus { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadReadStatus.fromJson({ + ...cleanedData, + readStatusId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateReadStatus { + constructor() {} + + toJson(): Record { + return { + lastReadAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateReadStatus { + constructor() {} + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + json[`lastReadAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteReadStatus {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the readStatuses collection for reading. + */ +export const readReadStatusCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`readStatuses`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadReadStatus => { + return ReadReadStatus.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadReadStatus` + ) + } + }) +} + +/** + * Provides a reference to a readStatus document for reading. + * @param readStatusId - The ID of the readStatus document to read. + */ +export const readReadStatusDocumentReference = ({ + chatRoomId, + readStatusId +}: { + chatRoomId: string + readStatusId: string +}): DocumentReference => + readReadStatusCollectionReference({ + chatRoomId + }).doc(readStatusId) + +/** + * Provides a reference to the readStatuses collection for creating. + */ +export const createReadStatusCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`readStatuses`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateReadStatus` + ) + }, + toFirestore: (obj: CreateReadStatus): DocumentData => { + return obj.toJson() + } + }) +} + +/** + * Provides a reference to a readStatus document for creating. + * @param readStatusId - The ID of the readStatus document to read. + */ +export const createReadStatusDocumentReference = ({ + chatRoomId, + readStatusId +}: { + chatRoomId: string + readStatusId: string +}): DocumentReference => + createReadStatusCollectionReference({ + chatRoomId + }).doc(readStatusId) + +/** + * Provides a reference to the readStatuses collection for updating. + */ +export const updateReadStatusCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`readStatuses`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateReadStatus` + ) + }, + toFirestore: (obj: UpdateReadStatus): DocumentData => { + return obj.toJson() + } + }) +} + +/** + * Provides a reference to a readStatus document for updating. + * @param readStatusId - The ID of the readStatus document to read. + */ +export const updateReadStatusDocumentReference = ({ + chatRoomId, + readStatusId +}: { + chatRoomId: string + readStatusId: string +}): DocumentReference => + updateReadStatusCollectionReference({ + chatRoomId + }).doc(readStatusId) + +/** + * Provides a reference to the readStatuses collection for deleting. + */ +export const deleteReadStatusCollectionReference = ({ + chatRoomId +}: { + chatRoomId: string +}): CollectionReference => { + return db + .collection(`chatRooms`) + .doc(chatRoomId) + .collection(`readStatuses`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteReadStatus` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteReadStatus` + ) + } + }) +} + +/** + * Provides a reference to a readStatus document for deleting. + * @param readStatusId - The ID of the readStatus document to read. + */ +export const deleteReadStatusDocumentReference = ({ + chatRoomId, + readStatusId +}: { + chatRoomId: string + readStatusId: string +}): DocumentReference => + deleteReadStatusCollectionReference({ + chatRoomId + }).doc(readStatusId) + +/** + * Manages queries against the readStatuses collection. + */ +export class ReadStatusQuery { + /** + * Fetches readStatus documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + chatRoomId, + queryBuilder, + compare + }: { + chatRoomId: string + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadReadStatus, rhs: ReadReadStatus) => number + }): Promise { + let query: Query = readReadStatusCollectionReference({ + chatRoomId + }) + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map((qds: QueryDocumentSnapshot) => + qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific readStatus document. + * @param readStatusId - The ID of the readStatus document to fetch. + */ + async fetchDocument({ + chatRoomId, + readStatusId + }: { + chatRoomId: string + readStatusId: string + }): Promise { + const ds = await readReadStatusDocumentReference({ + chatRoomId, + readStatusId + }).get() + return ds.data() + } + + /** + * Adds a readStatus document. + * @param createReadStatus - The readStatus details to add. + */ + async add({ + chatRoomId, + createReadStatus + }: { + chatRoomId: string + createReadStatus: CreateReadStatus + }): Promise> { + return createReadStatusCollectionReference({ chatRoomId }).add( + createReadStatus + ) + } + + /** + * Sets a readStatus document. + * @param readStatusId - The ID of the readStatus document to set. + * @param createReadStatus - The readStatus details to set. + * @param options - Options for the set operation. + */ + async set({ + chatRoomId, + readStatusId, + createReadStatus, + options + }: { + chatRoomId: string + readStatusId: string + createReadStatus: CreateReadStatus + options?: SetOptions + }): Promise { + if (options == undefined) { + return createReadStatusDocumentReference({ + chatRoomId, + readStatusId + }).set(createReadStatus) + } else { + return createReadStatusDocumentReference({ + chatRoomId, + readStatusId + }).set(createReadStatus, options) + } + } + + /** + * Updates a specific readStatus document. + * @param readStatusId - The ID of the readStatus document to update. + * @param updateReadStatus - The details for updating the readStatus. + */ + async update({ + chatRoomId, + readStatusId, + updateReadStatus + }: { + chatRoomId: string + readStatusId: string + updateReadStatus: UpdateReadStatus + }): Promise { + return updateReadStatusDocumentReference({ + chatRoomId, + readStatusId + }).update(updateReadStatus.toJson()) + } + + /** + * Deletes a specific readStatus document. + * @param readStatusId - The ID of the readStatus document to delete. + */ + async delete({ + chatRoomId, + readStatusId + }: { + chatRoomId: string + readStatusId: string + }): Promise { + return deleteReadStatusDocumentReference({ + chatRoomId, + readStatusId + }).delete() + } +} diff --git a/functions/src/firestore-documents/sampleTodo.flutterfireGen.ts b/functions/src/firestore-documents/sampleTodo.flutterfireGen.ts new file mode 100644 index 00000000..747c8fc1 --- /dev/null +++ b/functions/src/firestore-documents/sampleTodo.flutterfireGen.ts @@ -0,0 +1,395 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadSampleTodo { + constructor({ + sampleTodoId, + path, + title, + description, + isDone, + dueDateTime, + updatedAt + }: { + sampleTodoId: string + path: string + title: string + description: string + isDone: boolean + dueDateTime: Date + updatedAt?: Date + }) { + this.sampleTodoId = sampleTodoId + this.path = path + this.title = title + this.description = description + this.isDone = isDone + this.dueDateTime = dueDateTime + this.updatedAt = updatedAt + } + + readonly sampleTodoId: string + + readonly path: string + + readonly title: string + + readonly description: string + + readonly isDone: boolean + + readonly dueDateTime: Date + + readonly updatedAt?: Date + + private static fromJson(json: Record): ReadSampleTodo { + return new ReadSampleTodo({ + sampleTodoId: json[`sampleTodoId`] as string, + path: json[`path`] as string, + title: (json[`title`] as string | undefined) ?? ``, + description: (json[`description`] as string | undefined) ?? ``, + isDone: (json[`isDone`] as boolean | undefined) ?? false, + dueDateTime: (json[`dueDateTime`] as Timestamp).toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadSampleTodo { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadSampleTodo.fromJson({ + ...cleanedData, + sampleTodoId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateSampleTodo { + constructor({ + title, + description, + isDone, + dueDateTime + }: { + title: string + description: string + isDone: boolean + dueDateTime: Date + }) { + this.title = title + this.description = description + this.isDone = isDone + this.dueDateTime = dueDateTime + } + + readonly title: string + + readonly description: string + + readonly isDone: boolean + + readonly dueDateTime: Date + + toJson(): Record { + return { + title: this.title, + description: this.description, + isDone: this.isDone, + dueDateTime: this.dueDateTime, + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateSampleTodo { + constructor({ + title, + description, + isDone, + dueDateTime + }: { + title?: string + description?: string + isDone?: boolean + dueDateTime?: Date + }) { + this.title = title + this.description = description + this.isDone = isDone + this.dueDateTime = dueDateTime + } + + readonly title?: string + + readonly description?: string + + readonly isDone?: boolean + + readonly dueDateTime?: Date + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.title != undefined) { + json[`title`] = this.title + } + if (this.description != undefined) { + json[`description`] = this.description + } + if (this.isDone != undefined) { + json[`isDone`] = this.isDone + } + if (this.dueDateTime != undefined) { + json[`dueDateTime`] = this.dueDateTime + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteSampleTodo {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the sampleTodos collection for reading. + */ +export const readSampleTodoCollectionReference = db + .collection(`sampleTodos`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadSampleTodo => { + return ReadSampleTodo.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error(`toFirestore is not implemented for ReadSampleTodo`) + } + }) + +/** + * Provides a reference to a sampleTodo document for reading. + * @param sampleTodoId - The ID of the sampleTodo document to read. + */ +export const readSampleTodoDocumentReference = ({ + sampleTodoId +}: { + sampleTodoId: string +}): DocumentReference => + readSampleTodoCollectionReference.doc(sampleTodoId) + +/** + * Provides a reference to the sampleTodos collection for creating. + */ +export const createSampleTodoCollectionReference = db + .collection(`sampleTodos`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateSampleTodo` + ) + }, + toFirestore: (obj: CreateSampleTodo): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a sampleTodo document for creating. + * @param sampleTodoId - The ID of the sampleTodo document to read. + */ +export const createSampleTodoDocumentReference = ({ + sampleTodoId +}: { + sampleTodoId: string +}): DocumentReference => + createSampleTodoCollectionReference.doc(sampleTodoId) + +/** + * Provides a reference to the sampleTodos collection for updating. + */ +export const updateSampleTodoCollectionReference = db + .collection(`sampleTodos`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateSampleTodo` + ) + }, + toFirestore: (obj: UpdateSampleTodo): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a sampleTodo document for updating. + * @param sampleTodoId - The ID of the sampleTodo document to read. + */ +export const updateSampleTodoDocumentReference = ({ + sampleTodoId +}: { + sampleTodoId: string +}): DocumentReference => + updateSampleTodoCollectionReference.doc(sampleTodoId) + +/** + * Provides a reference to the sampleTodos collection for deleting. + */ +export const deleteSampleTodoCollectionReference = db + .collection(`sampleTodos`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteSampleTodo` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteSampleTodo` + ) + } + }) + +/** + * Provides a reference to a sampleTodo document for deleting. + * @param sampleTodoId - The ID of the sampleTodo document to read. + */ +export const deleteSampleTodoDocumentReference = ({ + sampleTodoId +}: { + sampleTodoId: string +}): DocumentReference => + deleteSampleTodoCollectionReference.doc(sampleTodoId) + +/** + * Manages queries against the sampleTodos collection. + */ +export class SampleTodoQuery { + /** + * Fetches sampleTodo documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: (query: Query) => Query + compare?: (lhs: ReadSampleTodo, rhs: ReadSampleTodo) => number + }): Promise { + let query: Query = readSampleTodoCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map((qds: QueryDocumentSnapshot) => + qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific sampleTodo document. + * @param sampleTodoId - The ID of the sampleTodo document to fetch. + */ + async fetchDocument({ + sampleTodoId + }: { + sampleTodoId: string + }): Promise { + const ds = await readSampleTodoDocumentReference({ + sampleTodoId + }).get() + return ds.data() + } + + /** + * Adds a sampleTodo document. + * @param createSampleTodo - The sampleTodo details to add. + */ + async add({ + createSampleTodo + }: { + createSampleTodo: CreateSampleTodo + }): Promise> { + return createSampleTodoCollectionReference.add(createSampleTodo) + } + + /** + * Sets a sampleTodo document. + * @param sampleTodoId - The ID of the sampleTodo document to set. + * @param createSampleTodo - The sampleTodo details to set. + * @param options - Options for the set operation. + */ + async set({ + sampleTodoId, + createSampleTodo, + options + }: { + sampleTodoId: string + createSampleTodo: CreateSampleTodo + options?: SetOptions + }): Promise { + if (options == undefined) { + return createSampleTodoDocumentReference({ + sampleTodoId + }).set(createSampleTodo) + } else { + return createSampleTodoDocumentReference({ + sampleTodoId + }).set(createSampleTodo, options) + } + } + + /** + * Updates a specific sampleTodo document. + * @param sampleTodoId - The ID of the sampleTodo document to update. + * @param updateSampleTodo - The details for updating the sampleTodo. + */ + async update({ + sampleTodoId, + updateSampleTodo + }: { + sampleTodoId: string + updateSampleTodo: UpdateSampleTodo + }): Promise { + return updateSampleTodoDocumentReference({ + sampleTodoId + }).update(updateSampleTodo.toJson()) + } + + /** + * Deletes a specific sampleTodo document. + * @param sampleTodoId - The ID of the sampleTodo document to delete. + */ + async delete({ + sampleTodoId + }: { + sampleTodoId: string + }): Promise { + return deleteSampleTodoDocumentReference({ + sampleTodoId + }).delete() + } +} diff --git a/functions/src/firestore-documents/userFcmToken.flutterfireGen.ts b/functions/src/firestore-documents/userFcmToken.flutterfireGen.ts new file mode 100644 index 00000000..bfa6749a --- /dev/null +++ b/functions/src/firestore-documents/userFcmToken.flutterfireGen.ts @@ -0,0 +1,394 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + FieldValue, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + Timestamp, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadUserFcmToken { + constructor({ + userFcmTokenId, + path, + userId, + token, + deviceInfo, + createdAt, + updatedAt + }: { + userFcmTokenId: string + path: string + userId: string + token: string + deviceInfo: string + createdAt?: Date + updatedAt?: Date + }) { + this.userFcmTokenId = userFcmTokenId + this.path = path + this.userId = userId + this.token = token + this.deviceInfo = deviceInfo + this.createdAt = createdAt + this.updatedAt = updatedAt + } + + readonly userFcmTokenId: string + + readonly path: string + + readonly userId: string + + readonly token: string + + readonly deviceInfo: string + + readonly createdAt?: Date + + readonly updatedAt?: Date + + private static fromJson(json: Record): ReadUserFcmToken { + return new ReadUserFcmToken({ + userFcmTokenId: json[`userFcmTokenId`] as string, + path: json[`path`] as string, + userId: json[`userId`] as string, + token: json[`token`] as string, + deviceInfo: (json[`deviceInfo`] as string | undefined) ?? ``, + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadUserFcmToken { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadUserFcmToken.fromJson({ + ...cleanedData, + userFcmTokenId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateUserFcmToken { + constructor({ + userId, + token, + deviceInfo + }: { + userId: string + token: string + deviceInfo: string + }) { + this.userId = userId + this.token = token + this.deviceInfo = deviceInfo + } + + readonly userId: string + + readonly token: string + + readonly deviceInfo: string + + toJson(): Record { + return { + userId: this.userId, + token: this.token, + deviceInfo: this.deviceInfo, + createdAt: FieldValue.serverTimestamp(), + updatedAt: FieldValue.serverTimestamp() + } + } +} + +export class UpdateUserFcmToken { + constructor({ + userId, + token, + deviceInfo, + createdAt + }: { + userId?: string + token?: string + deviceInfo?: string + createdAt?: Date + }) { + this.userId = userId + this.token = token + this.deviceInfo = deviceInfo + this.createdAt = createdAt + } + + readonly userId?: string + + readonly token?: string + + readonly deviceInfo?: string + + readonly createdAt?: Date + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.userId != undefined) { + json[`userId`] = this.userId + } + if (this.token != undefined) { + json[`token`] = this.token + } + if (this.deviceInfo != undefined) { + json[`deviceInfo`] = this.deviceInfo + } + if (this.createdAt != undefined) { + json[`createdAt`] = this.createdAt + } + json[`updatedAt`] = FieldValue.serverTimestamp() + return json + } +} + +export class DeleteUserFcmToken {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the userFcmTokens collection for reading. + */ +export const readUserFcmTokenCollectionReference = db + .collection(`userFcmTokens`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadUserFcmToken => { + return ReadUserFcmToken.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadUserFcmToken` + ) + } + }) + +/** + * Provides a reference to a userFcmToken document for reading. + * @param userFcmTokenId - The ID of the userFcmToken document to read. + */ +export const readUserFcmTokenDocumentReference = ({ + userFcmTokenId +}: { + userFcmTokenId: string +}): DocumentReference => + readUserFcmTokenCollectionReference.doc(userFcmTokenId) + +/** + * Provides a reference to the userFcmTokens collection for creating. + */ +export const createUserFcmTokenCollectionReference = db + .collection(`userFcmTokens`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateUserFcmToken` + ) + }, + toFirestore: (obj: CreateUserFcmToken): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a userFcmToken document for creating. + * @param userFcmTokenId - The ID of the userFcmToken document to read. + */ +export const createUserFcmTokenDocumentReference = ({ + userFcmTokenId +}: { + userFcmTokenId: string +}): DocumentReference => + createUserFcmTokenCollectionReference.doc(userFcmTokenId) + +/** + * Provides a reference to the userFcmTokens collection for updating. + */ +export const updateUserFcmTokenCollectionReference = db + .collection(`userFcmTokens`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateUserFcmToken` + ) + }, + toFirestore: (obj: UpdateUserFcmToken): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a userFcmToken document for updating. + * @param userFcmTokenId - The ID of the userFcmToken document to read. + */ +export const updateUserFcmTokenDocumentReference = ({ + userFcmTokenId +}: { + userFcmTokenId: string +}): DocumentReference => + updateUserFcmTokenCollectionReference.doc(userFcmTokenId) + +/** + * Provides a reference to the userFcmTokens collection for deleting. + */ +export const deleteUserFcmTokenCollectionReference = db + .collection(`userFcmTokens`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteUserFcmToken` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteUserFcmToken` + ) + } + }) + +/** + * Provides a reference to a userFcmToken document for deleting. + * @param userFcmTokenId - The ID of the userFcmToken document to read. + */ +export const deleteUserFcmTokenDocumentReference = ({ + userFcmTokenId +}: { + userFcmTokenId: string +}): DocumentReference => + deleteUserFcmTokenCollectionReference.doc(userFcmTokenId) + +/** + * Manages queries against the userFcmTokens collection. + */ +export class UserFcmTokenQuery { + /** + * Fetches userFcmToken documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: ( + query: Query + ) => Query + compare?: (lhs: ReadUserFcmToken, rhs: ReadUserFcmToken) => number + }): Promise { + let query: Query = readUserFcmTokenCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific userFcmToken document. + * @param userFcmTokenId - The ID of the userFcmToken document to fetch. + */ + async fetchDocument({ + userFcmTokenId + }: { + userFcmTokenId: string + }): Promise { + const ds = await readUserFcmTokenDocumentReference({ + userFcmTokenId + }).get() + return ds.data() + } + + /** + * Adds a userFcmToken document. + * @param createUserFcmToken - The userFcmToken details to add. + */ + async add({ + createUserFcmToken + }: { + createUserFcmToken: CreateUserFcmToken + }): Promise> { + return createUserFcmTokenCollectionReference.add(createUserFcmToken) + } + + /** + * Sets a userFcmToken document. + * @param userFcmTokenId - The ID of the userFcmToken document to set. + * @param createUserFcmToken - The userFcmToken details to set. + * @param options - Options for the set operation. + */ + async set({ + userFcmTokenId, + createUserFcmToken, + options + }: { + userFcmTokenId: string + createUserFcmToken: CreateUserFcmToken + options?: SetOptions + }): Promise { + if (options == undefined) { + return createUserFcmTokenDocumentReference({ + userFcmTokenId + }).set(createUserFcmToken) + } else { + return createUserFcmTokenDocumentReference({ + userFcmTokenId + }).set(createUserFcmToken, options) + } + } + + /** + * Updates a specific userFcmToken document. + * @param userFcmTokenId - The ID of the userFcmToken document to update. + * @param updateUserFcmToken - The details for updating the userFcmToken. + */ + async update({ + userFcmTokenId, + updateUserFcmToken + }: { + userFcmTokenId: string + updateUserFcmToken: UpdateUserFcmToken + }): Promise { + return updateUserFcmTokenDocumentReference({ + userFcmTokenId + }).update(updateUserFcmToken.toJson()) + } + + /** + * Deletes a specific userFcmToken document. + * @param userFcmTokenId - The ID of the userFcmToken document to delete. + */ + async delete({ + userFcmTokenId + }: { + userFcmTokenId: string + }): Promise { + return deleteUserFcmTokenDocumentReference({ + userFcmTokenId + }).delete() + } +} diff --git a/functions/src/firestore-documents/userSocialLogin.flutterfireGen.ts b/functions/src/firestore-documents/userSocialLogin.flutterfireGen.ts new file mode 100644 index 00000000..51043f20 --- /dev/null +++ b/functions/src/firestore-documents/userSocialLogin.flutterfireGen.ts @@ -0,0 +1,378 @@ +import * as admin from 'firebase-admin' +import { + DocumentData, + DocumentReference, + DocumentSnapshot, + Query, + QueryDocumentSnapshot, + QuerySnapshot, + SetOptions, + WriteResult +} from 'firebase-admin/firestore' + +export class ReadUserSocialLogin { + constructor({ + userSocialLoginId, + path, + isGoogleEnabled, + isAppleEnabled, + isLINEEnabled + }: { + userSocialLoginId: string + path: string + isGoogleEnabled: boolean + isAppleEnabled: boolean + isLINEEnabled: boolean + }) { + this.userSocialLoginId = userSocialLoginId + this.path = path + this.isGoogleEnabled = isGoogleEnabled + this.isAppleEnabled = isAppleEnabled + this.isLINEEnabled = isLINEEnabled + } + + readonly userSocialLoginId: string + + readonly path: string + + readonly isGoogleEnabled: boolean + + readonly isAppleEnabled: boolean + + readonly isLINEEnabled: boolean + + private static fromJson( + json: Record + ): ReadUserSocialLogin { + return new ReadUserSocialLogin({ + userSocialLoginId: json[`userSocialLoginId`] as string, + path: json[`path`] as string, + isGoogleEnabled: + (json[`isGoogleEnabled`] as boolean | undefined) ?? false, + isAppleEnabled: + (json[`isAppleEnabled`] as boolean | undefined) ?? false, + isLINEEnabled: + (json[`isLINEEnabled`] as boolean | undefined) ?? false + }) + } + + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadUserSocialLogin { + const data = ds.data()! + const cleanedData: Record = {} + for (const [key, value] of Object.entries(data)) { + cleanedData[key] = value === null ? undefined : value + } + return ReadUserSocialLogin.fromJson({ + ...cleanedData, + userSocialLoginId: ds.id, + path: ds.ref.path + }) + } +} + +export class CreateUserSocialLogin { + constructor({ + isGoogleEnabled, + isAppleEnabled, + isLINEEnabled + }: { + isGoogleEnabled: boolean + isAppleEnabled: boolean + isLINEEnabled: boolean + }) { + this.isGoogleEnabled = isGoogleEnabled + this.isAppleEnabled = isAppleEnabled + this.isLINEEnabled = isLINEEnabled + } + + readonly isGoogleEnabled: boolean + + readonly isAppleEnabled: boolean + + readonly isLINEEnabled: boolean + + toJson(): Record { + return { + isGoogleEnabled: this.isGoogleEnabled, + isAppleEnabled: this.isAppleEnabled, + isLINEEnabled: this.isLINEEnabled + } + } +} + +export class UpdateUserSocialLogin { + constructor({ + isGoogleEnabled, + isAppleEnabled, + isLINEEnabled + }: { + isGoogleEnabled?: boolean + isAppleEnabled?: boolean + isLINEEnabled?: boolean + }) { + this.isGoogleEnabled = isGoogleEnabled + this.isAppleEnabled = isAppleEnabled + this.isLINEEnabled = isLINEEnabled + } + + readonly isGoogleEnabled?: boolean + + readonly isAppleEnabled?: boolean + + readonly isLINEEnabled?: boolean + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} + if (this.isGoogleEnabled != undefined) { + json[`isGoogleEnabled`] = this.isGoogleEnabled + } + if (this.isAppleEnabled != undefined) { + json[`isAppleEnabled`] = this.isAppleEnabled + } + if (this.isLINEEnabled != undefined) { + json[`isLINEEnabled`] = this.isLINEEnabled + } + + return json + } +} + +export class DeleteUserSocialLogin {} + +/** + * A Cloud Firestore object which ignores `undefined` properties. + */ +const db = admin.firestore() +db.settings({ ignoreUndefinedProperties: true }) + +/** + * Provides a reference to the userSocialLogins collection for reading. + */ +export const readUserSocialLoginCollectionReference = db + .collection(`userSocialLogins`) + .withConverter({ + fromFirestore: (ds: DocumentSnapshot): ReadUserSocialLogin => { + return ReadUserSocialLogin.fromDocumentSnapshot(ds) + }, + toFirestore: () => { + throw new Error( + `toFirestore is not implemented for ReadUserSocialLogin` + ) + } + }) + +/** + * Provides a reference to a userSocialLogin document for reading. + * @param userSocialLoginId - The ID of the userSocialLogin document to read. + */ +export const readUserSocialLoginDocumentReference = ({ + userSocialLoginId +}: { + userSocialLoginId: string +}): DocumentReference => + readUserSocialLoginCollectionReference.doc(userSocialLoginId) + +/** + * Provides a reference to the userSocialLogins collection for creating. + */ +export const createUserSocialLoginCollectionReference = db + .collection(`userSocialLogins`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for CreateUserSocialLogin` + ) + }, + toFirestore: (obj: CreateUserSocialLogin): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a userSocialLogin document for creating. + * @param userSocialLoginId - The ID of the userSocialLogin document to read. + */ +export const createUserSocialLoginDocumentReference = ({ + userSocialLoginId +}: { + userSocialLoginId: string +}): DocumentReference => + createUserSocialLoginCollectionReference.doc(userSocialLoginId) + +/** + * Provides a reference to the userSocialLogins collection for updating. + */ +export const updateUserSocialLoginCollectionReference = db + .collection(`userSocialLogins`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for UpdateUserSocialLogin` + ) + }, + toFirestore: (obj: UpdateUserSocialLogin): DocumentData => { + return obj.toJson() + } + }) + +/** + * Provides a reference to a userSocialLogin document for updating. + * @param userSocialLoginId - The ID of the userSocialLogin document to read. + */ +export const updateUserSocialLoginDocumentReference = ({ + userSocialLoginId +}: { + userSocialLoginId: string +}): DocumentReference => + updateUserSocialLoginCollectionReference.doc(userSocialLoginId) + +/** + * Provides a reference to the userSocialLogins collection for deleting. + */ +export const deleteUserSocialLoginCollectionReference = db + .collection(`userSocialLogins`) + .withConverter({ + fromFirestore: () => { + throw new Error( + `fromFirestore is not implemented for DeleteUserSocialLogin` + ) + }, + toFirestore: (): DocumentData => { + throw new Error( + `toFirestore is not implemented for DeleteUserSocialLogin` + ) + } + }) + +/** + * Provides a reference to a userSocialLogin document for deleting. + * @param userSocialLoginId - The ID of the userSocialLogin document to read. + */ +export const deleteUserSocialLoginDocumentReference = ({ + userSocialLoginId +}: { + userSocialLoginId: string +}): DocumentReference => + deleteUserSocialLoginCollectionReference.doc(userSocialLoginId) + +/** + * Manages queries against the userSocialLogins collection. + */ +export class UserSocialLoginQuery { + /** + * Fetches userSocialLogin documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. + */ + async fetchDocuments({ + queryBuilder, + compare + }: { + queryBuilder?: ( + query: Query + ) => Query + compare?: (lhs: ReadUserSocialLogin, rhs: ReadUserSocialLogin) => number + }): Promise { + let query: Query = + readUserSocialLoginCollectionReference + if (queryBuilder != undefined) { + query = queryBuilder(query) + } + const qs: QuerySnapshot = await query.get() + let result = qs.docs.map( + (qds: QueryDocumentSnapshot) => qds.data() + ) + if (compare != undefined) { + result = result.sort(compare) + } + return result + } + + /** + * Fetches a specific userSocialLogin document. + * @param userSocialLoginId - The ID of the userSocialLogin document to fetch. + */ + async fetchDocument({ + userSocialLoginId + }: { + userSocialLoginId: string + }): Promise { + const ds = await readUserSocialLoginDocumentReference({ + userSocialLoginId + }).get() + return ds.data() + } + + /** + * Adds a userSocialLogin document. + * @param createUserSocialLogin - The userSocialLogin details to add. + */ + async add({ + createUserSocialLogin + }: { + createUserSocialLogin: CreateUserSocialLogin + }): Promise> { + return createUserSocialLoginCollectionReference.add( + createUserSocialLogin + ) + } + + /** + * Sets a userSocialLogin document. + * @param userSocialLoginId - The ID of the userSocialLogin document to set. + * @param createUserSocialLogin - The userSocialLogin details to set. + * @param options - Options for the set operation. + */ + async set({ + userSocialLoginId, + createUserSocialLogin, + options + }: { + userSocialLoginId: string + createUserSocialLogin: CreateUserSocialLogin + options?: SetOptions + }): Promise { + if (options == undefined) { + return createUserSocialLoginDocumentReference({ + userSocialLoginId + }).set(createUserSocialLogin) + } else { + return createUserSocialLoginDocumentReference({ + userSocialLoginId + }).set(createUserSocialLogin, options) + } + } + + /** + * Updates a specific userSocialLogin document. + * @param userSocialLoginId - The ID of the userSocialLogin document to update. + * @param updateUserSocialLogin - The details for updating the userSocialLogin. + */ + async update({ + userSocialLoginId, + updateUserSocialLogin + }: { + userSocialLoginId: string + updateUserSocialLogin: UpdateUserSocialLogin + }): Promise { + return updateUserSocialLoginDocumentReference({ + userSocialLoginId + }).update(updateUserSocialLogin.toJson()) + } + + /** + * Deletes a specific userSocialLogin document. + * @param userSocialLoginId - The ID of the userSocialLogin document to delete. + */ + async delete({ + userSocialLoginId + }: { + userSocialLoginId: string + }): Promise { + return deleteUserSocialLoginDocumentReference({ + userSocialLoginId + }).delete() + } +} diff --git a/functions/src/firebase-documents/worker.flutterfireGen.ts b/functions/src/firestore-documents/worker.flutterfireGen.ts similarity index 55% rename from functions/src/firebase-documents/worker.flutterfireGen.ts rename to functions/src/firestore-documents/worker.flutterfireGen.ts index 4211ec15..76d1860e 100644 --- a/functions/src/firebase-documents/worker.flutterfireGen.ts +++ b/functions/src/firestore-documents/worker.flutterfireGen.ts @@ -1,9 +1,14 @@ import * as admin from 'firebase-admin' import { + DocumentData, DocumentReference, + DocumentSnapshot, FieldValue, + Query, QueryDocumentSnapshot, QuerySnapshot, + SetOptions, + Timestamp, WriteResult } from 'firebase-admin/firestore' @@ -55,18 +60,12 @@ export class ReadWorker { displayName: (json[`displayName`] as string | undefined) ?? ``, imageUrl: (json[`imageUrl`] as string | undefined) ?? ``, isHost: (json[`isHost`] as boolean | undefined) ?? false, - createdAt: ( - json[`createdAt`] as FirebaseFirestore.Timestamp | undefined - )?.toDate(), - updatedAt: ( - json[`updatedAt`] as FirebaseFirestore.Timestamp | undefined - )?.toDate() + createdAt: (json[`createdAt`] as Timestamp | undefined)?.toDate(), + updatedAt: (json[`updatedAt`] as Timestamp | undefined)?.toDate() }) } - static fromDocumentSnapshot( - ds: FirebaseFirestore.DocumentSnapshot - ): ReadWorker { + static fromDocumentSnapshot(ds: DocumentSnapshot): ReadWorker { const data = ds.data()! const cleanedData: Record = {} for (const [key, value] of Object.entries(data)) { @@ -101,8 +100,6 @@ export class CreateWorker { readonly isHost: boolean - readonly createdAt?: Date - toJson(): Record { return { displayName: this.displayName, @@ -140,8 +137,10 @@ export class UpdateWorker { readonly createdAt?: Date - toJson(): Record { - const json: Record = {} + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJson(): Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const json: Record = {} if (this.displayName != undefined) { json[`displayName`] = this.displayName } @@ -152,15 +151,15 @@ export class UpdateWorker { json[`isHost`] = this.isHost } if (this.createdAt != undefined) { - json[`createdAt`] = FirebaseFirestore.Timestamp.fromDate( - this.createdAt - ) + json[`createdAt`] = this.createdAt } json[`updatedAt`] = FieldValue.serverTimestamp() return json } } +export class DeleteWorker {} + /** * A Cloud Firestore object which ignores `undefined` properties. */ @@ -168,126 +167,121 @@ const db = admin.firestore() db.settings({ ignoreUndefinedProperties: true }) /** - * A CollectionReference to the workers collection for reading. - * @type {FirebaseFirestore.CollectionReference} + * Provides a reference to the workers collection for reading. */ export const readWorkerCollectionReference = db .collection(`workers`) .withConverter({ - fromFirestore: (ds: FirebaseFirestore.DocumentSnapshot): ReadWorker => { + fromFirestore: (ds: DocumentSnapshot): ReadWorker => { return ReadWorker.fromDocumentSnapshot(ds) }, - toFirestore: (): FirebaseFirestore.DocumentData => { - throw Error(`toFirestore is not implemented for ReadWorker`) + toFirestore: () => { + throw new Error(`toFirestore is not implemented for ReadWorker`) } }) /** - * A DocumentReference to a worker document for reading. - * @param {string} workerId - The ID of the worker document to read. - * @returns {FirebaseFirestore.DocumentReference} + * Provides a reference to a worker document for reading. + * @param workerId - The ID of the worker document to read. */ export const readWorkerDocumentReference = ({ workerId }: { workerId: string -}): FirebaseFirestore.DocumentReference => - readWorkerCollectionReference.doc(workerId) +}): DocumentReference => readWorkerCollectionReference.doc(workerId) /** - * A CollectionReference to the workers collection for creating. - * @type {FirebaseFirestore.CollectionReference} + * Provides a reference to the workers collection for creating. */ export const createWorkerCollectionReference = db .collection(`workers`) .withConverter({ - fromFirestore: (): CreateWorker => { + fromFirestore: () => { throw new Error(`fromFirestore is not implemented for CreateWorker`) }, - toFirestore: (obj: CreateWorker): FirebaseFirestore.DocumentData => { + toFirestore: (obj: CreateWorker): DocumentData => { return obj.toJson() } }) /** - * A DocumentReference to a worker document for creating. - * @param {string} workerId - The ID of the worker document to create. - * @returns {FirebaseFirestore.DocumentReference} + * Provides a reference to a worker document for creating. + * @param workerId - The ID of the worker document to read. */ export const createWorkerDocumentReference = ({ workerId }: { workerId: string -}): FirebaseFirestore.DocumentReference => +}): DocumentReference => createWorkerCollectionReference.doc(workerId) /** - * A CollectionReference to the workers collection for updating. - * @type {FirebaseFirestore.CollectionReference} + * Provides a reference to the workers collection for updating. */ export const updateWorkerCollectionReference = db .collection(`workers`) .withConverter({ - fromFirestore: (): CreateWorker => { - throw new Error(`fromFirestore is not implemented for CreateWorker`) + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for UpdateWorker`) }, - toFirestore: (obj: UpdateWorker): FirebaseFirestore.DocumentData => { + toFirestore: (obj: UpdateWorker): DocumentData => { return obj.toJson() } }) /** - * A DocumentReference to a worker document for updating. - * @param {string} workerId - The ID of the worker document to update. - * @returns {FirebaseFirestore.DocumentReference} + * Provides a reference to a worker document for updating. + * @param workerId - The ID of the worker document to read. */ export const updateWorkerDocumentReference = ({ workerId }: { workerId: string -}): FirebaseFirestore.DocumentReference => +}): DocumentReference => updateWorkerCollectionReference.doc(workerId) /** - * A CollectionReference to the workers collection for deleting. - * @type {FirebaseFirestore.CollectionReference} + * Provides a reference to the workers collection for deleting. */ -export const deleteWorkerCollectionReference = db.collection(`workers`) +export const deleteWorkerCollectionReference = db + .collection(`workers`) + .withConverter({ + fromFirestore: () => { + throw new Error(`fromFirestore is not implemented for DeleteWorker`) + }, + toFirestore: (): DocumentData => { + throw new Error(`toFirestore is not implemented for DeleteWorker`) + } + }) /** - * A DocumentReference to a worker document for deleting. - * @param {string} workerId - The ID of the worker document to delete. - * @returns {FirebaseFirestore.DocumentReference} + * Provides a reference to a worker document for deleting. + * @param workerId - The ID of the worker document to read. */ export const deleteWorkerDocumentReference = ({ workerId }: { workerId: string -}): FirebaseFirestore.DocumentReference => +}): DocumentReference => deleteWorkerCollectionReference.doc(workerId) /** - * A query manager to execute queries against the Worker collection. + * Manages queries against the workers collection. */ export class WorkerQuery { /** - * Fetches ReadWorker documents. - * @param {Object} options - Options for the query. - * @param {Function} options.queryBuilder - A function to build the query. - * @param {Function} options.compare - A function to compare the results. - * @returns {Promise} + * Fetches worker documents. + * @param queryBuilder - Function to modify the query. + * @param compare - Function to sort the results. */ async fetchDocuments({ queryBuilder, compare }: { - queryBuilder?: ( - query: FirebaseFirestore.Query - ) => FirebaseFirestore.Query + queryBuilder?: (query: Query) => Query compare?: (lhs: ReadWorker, rhs: ReadWorker) => number - } = {}): Promise { - let query: FirebaseFirestore.Query = - readWorkerCollectionReference + }): Promise { + let query: Query = readWorkerCollectionReference if (queryBuilder != undefined) { query = queryBuilder(query) } @@ -302,25 +296,23 @@ export class WorkerQuery { } /** - * Fetches a specified ReadWorker document. - * @param {Object} options - Options for the query. - * @param {string} options.workerId - The ID of the worker document to fetch. - * @returns {Promise} + * Fetches a specific worker document. + * @param workerId - The ID of the worker document to fetch. */ async fetchDocument({ workerId }: { workerId: string }): Promise { - const ds = await readWorkerDocumentReference({ workerId }).get() + const ds = await readWorkerDocumentReference({ + workerId + }).get() return ds.data() } /** - * Adds a Worker document. - * @param {Object} options - Options for the query. - * @param {CreateWorker} options.createWorker - The worker document to add. - * @returns {Promise>} + * Adds a worker document. + * @param createWorker - The worker details to add. */ async add({ createWorker @@ -331,12 +323,10 @@ export class WorkerQuery { } /** - * Sets a Worker document. - * @param {Object} options - Options for the query. - * @param {string} options.workerId - The ID of the worker document to set. - * @param {CreateWorker} options.createWorker - The worker document to set. - * @param {FirebaseFirestore.SetOptions} options.options - Options for the set operation. - * @returns {Promise} + * Sets a worker document. + * @param workerId - The ID of the worker document to set. + * @param createWorker - The worker details to set. + * @param options - Options for the set operation. */ async set({ workerId, @@ -345,24 +335,23 @@ export class WorkerQuery { }: { workerId: string createWorker: CreateWorker - options?: FirebaseFirestore.SetOptions + options?: SetOptions }): Promise { if (options == undefined) { - return createWorkerDocumentReference({ workerId }).set(createWorker) + return createWorkerDocumentReference({ + workerId + }).set(createWorker) } else { - return createWorkerDocumentReference({ workerId }).set( - createWorker, - options - ) + return createWorkerDocumentReference({ + workerId + }).set(createWorker, options) } } /** - * Updates a specified Worker document. - * @param {Object} options - Options for the query. - * @param {string} options.workerId - The ID of the worker document to update. - * @param {UpdateWorker} options.updateWorker - The worker document to update. - * @returns {Promise} + * Updates a specific worker document. + * @param workerId - The ID of the worker document to update. + * @param updateWorker - The details for updating the worker. */ async update({ workerId, @@ -371,18 +360,18 @@ export class WorkerQuery { workerId: string updateWorker: UpdateWorker }): Promise { - return updateWorkerDocumentReference({ workerId }).update( - updateWorker.toJson() - ) + return updateWorkerDocumentReference({ + workerId + }).update(updateWorker.toJson()) } /** - * Deletes a specified Worker document. - * @param {Object} options - Options for the query. - * @param {string} options.workerId - The ID of the worker document to delete. - * @returns {Promise} + * Deletes a specific worker document. + * @param workerId - The ID of the worker document to delete. */ async delete({ workerId }: { workerId: string }): Promise { - return deleteWorkerDocumentReference({ workerId }).delete() + return deleteWorkerDocumentReference({ + workerId + }).delete() } }