abstract read()

in libs/newsletters-data-client/src/lib/newsletter-storage/NewsletterStorage.ts [35:118]


	abstract read(
		listId: number,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract readWithMeta(
		listId: number,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract readByName(
		identityName: string,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract update(
		listId: number,
		modifications: Partial<NewsletterData>,
		user: UserProfile,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract replace(
		listId: number,
		newsletter: NewsletterData,
		user: UserProfile,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract delete(
		listId: number,
	): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta>
		| UnsuccessfulStorageResponse
	>;

	abstract list(): Promise<
		| SuccessfulStorageResponse<NewsletterDataWithoutMeta[]>
		| UnsuccessfulStorageResponse
	>;

	getModificationError(
		modifications: Partial<NewsletterData>,
	): UnsuccessfulStorageResponse | undefined {
		const problems: string[] = [];
		const propertiesChanged = Object.keys(modifications);

		const forbiddenKeyChanges = propertiesChanged.filter((property) =>
			IMMUTABLE_PROPERTIES.includes(property),
		);

		if (forbiddenKeyChanges.length > 0) {
			problems.push(
				`Cannot change ${forbiddenKeyChanges
					.map((key) => `"${key}"`)
					.join(' or ')} on a newsletter.`,
			);
		}

		if (!isPartialNewsletterData(modifications)) {
			problems.push(
				'Not all fields are of the required type or in the right format.',
			);
		}

		if (problems.length === 0) {
			return undefined;
		}
		return {
			ok: false,
			message: problems.join(' '),
			reason: StorageRequestFailureReason.InvalidDataInput,
		};
	}