All files / app/service publicTrips.ts

13.04% Statements 6/46
0% Branches 0/20
0% Functions 0/4
14.63% Lines 6/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106            107x   107x   106x                                         106x                                                   106x                                             106x                                                  
import {
  CreatePublicTripReq,
  ListPublicTripsByUserReq,
  ListPublicTripsReq,
  PublicTripStatus,
  UpdatePublicTripReq,
} from "proto/public_trips_pb";
 
import client from "./client";
 
export async function listPublicTrips({
  communityId,
  pageToken,
  pageSize,
}: {
  communityId: number;
  pageToken?: string;
  pageSize?: number;
}) {
  const req = new ListPublicTripsReq();
  req.setCommunityId(communityId);
  if (pageToken) {
    req.setPageToken(pageToken);
  }
  if (pageSize) {
    req.setPageSize(pageSize);
  }
  const res = await client.publicTrips.listPublicTrips(req);
  return res.toObject();
}
 
export async function listPublicTripsByUser({
  userId,
  pageToken,
  pageSize,
  ascending,
}: {
  userId: number;
  pageToken?: string;
  pageSize?: number;
  ascending?: boolean;
}) {
  const req = new ListPublicTripsByUserReq();
  req.setUserId(userId);
  if (pageToken) {
    req.setPageToken(pageToken);
  }
  if (pageSize) {
    req.setPageSize(pageSize);
  }
  if (ascending !== undefined) {
    req.setAscending(ascending);
  }
  const res = await client.publicTrips.listPublicTripsByUser(req);
  return res.toObject();
}
 
export async function createPublicTrip({
  communityId,
  fromDate,
  toDate,
  description,
  sameGenderOnly,
}: {
  communityId: number;
  fromDate: string;
  toDate: string;
  description: string;
  sameGenderOnly: boolean;
}) {
  const req = new CreatePublicTripReq();
  req.setCommunityId(communityId);
  req.setFromDate(fromDate);
  req.setToDate(toDate);
  req.setDescription(description);
  req.setSameGenderOnly(sameGenderOnly);
  const res = await client.publicTrips.createPublicTrip(req);
  return res.toObject();
}
 
export async function updatePublicTrip({
  tripId,
  fromDate,
  toDate,
  description,
  status,
  sameGenderOnly,
}: {
  tripId: number;
  fromDate?: string;
  toDate?: string;
  description?: string;
  status?: PublicTripStatus;
  sameGenderOnly?: boolean;
}) {
  const req = new UpdatePublicTripReq();
  req.setTripId(tripId);
  if (fromDate !== undefined) req.setFromDate(fromDate);
  if (toDate !== undefined) req.setToDate(toDate);
  if (description !== undefined) req.setDescription(description);
  if (status !== undefined) req.setStatus(status);
  if (sameGenderOnly !== undefined) req.setSameGenderOnly(sameGenderOnly);
  const res = await client.publicTrips.updatePublicTrip(req);
  return res.toObject();
}