Repository: directus/directus
File: api/src/services/payload.ts (TypeScript)

Code before:
		const geometryColumns = fieldsInCollection.filter(([_, field]) => field.type.startsWith('geometry'));

		for (const [name] of geometryColumns) {
			for (const payload of payloads) {
				if (payload[name]) {
					payload[name] = process(payload[name]);
				}
			}
		}

		return payloads;
	}

	/**
	 * Knex returns `datetime` and `date` columns as Date.. This is wrong for date / datetime, as those
	 * shouldn't return with time / timezone info respectively
	 */
	processDates(
		payloads: Partial<Record<string, any>>[],
		action: Action,
		aliasMap: Record<string, string> = {},
	): Partial<Record<string, any>>[] {
		const fieldsInCollection = Object.entries(this.schema.collections[this.collection]!.fields);

		for (const alias in aliasMap) {
			const field = fieldsInCollection.find(([name, _]) => name === aliasMap[alias]);

			if (field) {
				fieldsInCollection.push([
					alias,
					{
						...field[1],
						field: alias,
					},
				]);
			}
		}

		const dateColumns = fieldsInCollection.filter(([_name, field]) =>
			['dateTime', 'date', 'timestamp'].includes(field.type),
		);

		const timeColumns = fieldsInCollection.filter(([_name, field]) => {
			return field.type === 'time';
		});

		if (dateColumns.length === 0 && timeColumns.length === 0) return payloads;

		for (const [name, dateColumn] of dateColumns) {
			for (const payload of payloads) {
				let value: number | string | Date = payload[name];

Review comment (performance):
In terms of performance an object lookup should be faster and since we use the key name it should not be an issue?

e.g.

```suggestion
			const field = this.schema.collections[this.collection]!.fields[aliasMap[alias]];
```

Code after:
		const process =
			action == 'read'
				? (value: any) => (typeof value === 'string' ? wktToGeoJSON(value) : value)
				: (value: any) => this.helpers.st.fromGeoJSON(typeof value == 'string' ? parseJSON(value) : value);

		const geometryColumns = fieldEntries.filter(([_, field]) => field.type.startsWith('geometry'));

		for (const [name] of geometryColumns) {
			for (const payload of payloads) {
				if (payload[name]) {
					payload[name] = process(payload[name]);
				}
			}
		}

		return payloads;
	}

	/**
	 * Knex returns `datetime` and `date` columns as Date.. This is wrong for date / datetime, as those
	 * shouldn't return with time / timezone info respectively
	 */
	processDates(
		fieldEntries: [string, FieldOverview][],
		payloads: Partial<Record<string, any>>[],
		action: Action,
		aliasMap: Record<string, string> = {},
	): Partial<Record<string, any>>[] {
		for (const alias in aliasMap) {
			const aliasedField = aliasMap[alias];
			const field = this.schema.collections[this.collection]!.fields[aliasedField!];

			if (field) {
				fieldEntries.push([
					alias,
					{
						...field,
						field: alias,
					},
				]);
			}
		}

		const dateColumns = fieldEntries.filter(([_name, field]) => ['dateTime', 'date', 'timestamp'].includes(field.type));

		const timeColumns = fieldEntries.filter(([_name, field]) => {
			return field.type === 'time';
		});

		if (dateColumns.length === 0 && timeColumns.length === 0) return payloads;