Skip to content

Commit

Permalink
Fix: api journey (#2749)
Browse files Browse the repository at this point in the history
* fix: return 422 if version >=3.1

* fix: avoid journey without phone and phone_trunc

* fix: return legacy_id
  • Loading branch information
nmrgt authored Jan 14, 2025
1 parent 7d33653 commit 9e37c21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { semver } from "@/deps.ts";
import { provider } from "@/ilos/common/Decorators.ts";
import { PostgresConnection } from "@/ilos/connection-postgres/index.ts";
import { CarpoolLabel, CarpoolStatus } from "../interfaces/database/label.ts";
Expand All @@ -24,7 +23,7 @@ export class CarpoolStatusService {
anomaly: Array<CarpoolLabel<unknown>>;
fraud: Array<CarpoolLabel<unknown>>;
terms: Array<CarpoolLabel<unknown>>;
legacy_id?: number;
legacy_id: number;
} | undefined
> {
const statusResult = await this.statusRepository
Expand Down Expand Up @@ -58,7 +57,7 @@ export class CarpoolStatusService {
anomaly,
fraud,
terms,
...(semver.satisfies(semver.parse("3.2.0"), semver.parseRange(api_version)) ? { journey_id: legacy_id } : {}),
legacy_id,
};
}

Expand Down
17 changes: 16 additions & 1 deletion api/src/pdc/services/acquisition/actions/CreateJourneyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,26 @@ export class CreateJourneyAction extends AbstractAction {
if (end > now || start > end) {
throw new ParseErrorException("Journeys cannot happen in the future");
}

if (
!journey.driver?.identity?.phone &&
!journey.driver?.identity?.phone_trunc
) {
throw new InvalidRequestException(`driver.identity should have a phone or phone_trunc`);
}
if (
!journey.passenger?.identity?.phone &&
!journey.passenger?.identity?.phone_trunc
) {
throw new InvalidRequestException(`passenger.identity should have a phone or phone_trunc`);
}
}

protected validateResults(context: ContextType, result: RegisterResponse): void {
if (result.terms_violation_error_labels.length) {
if (semver.satisfies(semver.parse("3.1.0"), semver.parseRange(context.call?.api_version_range || "3.0"))) {
if (
semver.rangeIntersects(semver.parseRange(">=3.1"), semver.parseRange(context.call?.api_version_range || "3.0"))
) {
throw new UnprocessableRequestException({
terms_violation_labels: result.terms_violation_error_labels,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ContextType, handler, NotFoundException } from "@/ilos/common/index.ts"
import { Action as AbstractAction } from "@/ilos/core/index.ts";
import { copyGroupIdAndApplyGroupPermissionMiddlewares } from "@/pdc/providers/middleware/index.ts";

import { semver } from "@/deps.ts";
import { castToStatusEnum } from "@/pdc/providers/carpool/helpers/castStatus.ts";
import { CarpoolStatusService } from "@/pdc/providers/carpool/providers/CarpoolStatusService.ts";
import { handlerConfig, ParamsInterface, ResultInterface } from "../contracts/status.contract.ts";
Expand Down Expand Up @@ -42,6 +43,12 @@ export class StatusJourneyAction extends AbstractAction {
fraud_error_labels: result.fraud.map((f) => f.label),
anomaly_error_details: result.anomaly as any,
terms_violation_details: result.terms.map((f) => f.label),
...(semver.rangeIntersects(
semver.parseRange(">=3.2"),
semver.parseRange(context.call?.api_version_range || "3.0"),
)
? { journey_id: result.legacy_id }
: {}),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface ResultInterface {
fraud_error_labels?: string[];
anomaly_error_details?: AnomalyErrorDetails[];
terms_violation_details?: string[];
journey_id?: number;
}

export const handlerConfig = {
Expand Down

0 comments on commit 9e37c21

Please sign in to comment.