Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Firebase packages #493

Merged
merged 6 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions libs/firebase/data-access/src/lib/firestore/batch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { DocumentReference, WriteBatch } from '@angular/fire/firestore';
import {
DocumentReference,
FieldValue,
WriteBatch,
} from '@angular/fire/firestore';

export interface BatchSet<T> {
endpoint: string;
id: string;
data: T;
}

export type BatchUpdate = BatchSet<{ [fieldPath: string]: unknown }>;
export type BatchUpdate = BatchSet<{
[x: string]: FieldValue | Partial<unknown> | undefined;
}>;

export class Batch {
constructor(
Expand All @@ -19,7 +25,7 @@ export class Batch {

set<T>({ endpoint, id, data }: BatchSet<T>): Batch {
const docRef = this._getDocRef<T>(endpoint, id);
this._batch.set<T>(docRef, data);
this._batch.set(docRef, data);
return this;
}

Expand All @@ -28,19 +34,19 @@ export class Batch {
return this;
}

update({ endpoint, id, data }: BatchUpdate): Batch {
const docRef = this._getDocRef(endpoint, id);
update<T>({ endpoint, id, data }: BatchUpdate): Batch {
const docRef = this._getDocRef<T>(endpoint, id);
this._batch.update(docRef, data);
return this;
}

updateMultiple(updates: BatchUpdate[]): Batch {
updates.forEach((update) => this.update(update));
updateMultiple<T>(updates: BatchUpdate[]): Batch {
updates.forEach((update) => this.update<T>(update));
return this;
}

delete(endpoint: string, id: string): Batch {
const docRef = this._getDocRef(endpoint, id);
delete<T>(endpoint: string, id: string): Batch {
const docRef = this._getDocRef<T>(endpoint, id);
this._batch.delete(docRef);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DocumentReference,
Firestore,
Transaction,
UpdateData,
WriteBatch,
arrayRemove,
arrayUnion,
Expand Down Expand Up @@ -77,7 +76,7 @@ export class FirestoreService {
data: Partial<T>
): Promise<void> {
const doc = this._getDocRef<T>(endpoint, id);
return await updateDoc<T>(doc, data as UpdateData<T>);
return await updateDoc(doc, data);
}

async delete<T>(endpoint: string, id: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// TODO: remove this chunk after newer version of Jest is installed
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

import { TAG_DTOS } from '@atocha/menu-matriarch/tags/data-access';
import { INGREDIENT_DTOS } from '@atocha/menu-matriarch/ingredients/data-access';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// TODO: remove this chunk after newer version of Jest is installed
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

import { mapIngredientTypeDtoToIngredientType } from './map-ingredient-type-dto-to-ingredient-type';
import { INGREDIENT_DTOS, INGREDIENT_TYPE_DTOS } from '../mock-data';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// TODO: remove this chunk after newer version of Jest is installed
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

import { PIZZA, SALAD } from '@atocha/menu-matriarch/dishes/data-access';
import { TAG_DTOS } from '@atocha/menu-matriarch/tags/data-access';
import { mapMealDtoToMeal } from './map-meal-dto-to-meal';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// TODO: remove this chunk after newer version of Jest is installed
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

import { PIZZA, SALAD } from '@atocha/menu-matriarch/dishes/data-access';
import { mapMenuDtoToMenu } from './map-menu-dto-to-menu';
import { MENU_DTO } from '../mock-data';
Expand Down