Skip to content

Commit

Permalink
Merge branch 'main' into issues-96
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Sep 24, 2024
2 parents 824a228 + 1798547 commit 980501d
Show file tree
Hide file tree
Showing 21 changed files with 901 additions and 897 deletions.
3 changes: 1 addition & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# FROM oven/bun:alpine
FROM oven/bun:1.1.4-alpine
FROM oven/bun:alpine

WORKDIR /usr/api

Expand Down
4 changes: 2 additions & 2 deletions api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "drizzle-kit";
import { DB_CA, DB_DATABASE, DB_HOST, DB_URL } from "./src/utils/constants";
import { DB_DATABASE, DB_HOST, DB_URL, ENVIRONMENT } from "./src/utils/constants";

export default defineConfig({
schema: 'drizzle/schema.ts',
Expand All @@ -8,7 +8,7 @@ export default defineConfig({
dbCredentials: {
url: DB_URL,
database: DB_DATABASE,
ssl: DB_HOST.includes('neon') ? "require" : { ca: DB_CA },
ssl: DB_HOST.includes('neon') || ENVIRONMENT === "production" ? "require" : undefined,
},
verbose: true,
strict: true,
Expand Down
10 changes: 5 additions & 5 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/nodemailer": "^6.4.14",
"@types/nodemailer": "^6.4.16",
"@types/validator": "^13.12.2",
"drizzle-kit": "^0.24.2",
"typescript": "^5.4.5"
"typescript": "^5.6.2"
},
"dependencies": {
"@capgo/s3-lite-client": "^0.1.8",
"@sentry/bun": "^8.26.0",
"@trpc/server": "11.0.0-rc.502",
"@types/validator": "^13.12.2",
"@sentry/bun": "^8.30.0",
"@trpc/server": "11.0.0-rc.528",
"cors": "^2.8.5",
"drizzle-orm": "^0.33.0",
"nodemailer": "^6.9.14",
Expand Down
2 changes: 1 addition & 1 deletion api/src/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const authRouter = router({

if (existingForgotPassword) {
if (existingForgotPassword.time.getTime() + 18000 * 1000 < Date.now()) {
// The user's existing forgot password request has expired.'
// The user's existing forgot password request has expired.
// We will delete it, and proceed with creating a new one.
await db.delete(forgot_password).where(eq(forgot_password.id, existingForgotPassword.id));
} else {
Expand Down
2 changes: 1 addition & 1 deletion api/src/routers/car.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const carRouter = router({
make: z.string(),
model: z.string(),
year: z.string(),
color: z.string(),
color: z.string().toLowerCase(),
photo: z.instanceof(File),
});

Expand Down
4 changes: 2 additions & 2 deletions api/src/routers/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export const ratingRouter = router({
} else {
const numberOfRatingsForUserCount = await db
.select({ count: count() })
.from(user)
.where(eq(user.id, u.id));
.from(rating)
.where(eq(rating.rated_id, input.userId));

const numberOfRatingsForUser = numberOfRatingsForUserCount[0].count;

Expand Down
4 changes: 0 additions & 4 deletions api/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const SENTRY_URL = process.env.SENTRY_URL;

export const DB_HOST = process.env.DB_HOST || "localhost";

export const DB_DATABASE = process.env.DB_DATABASE || "beep";
Expand All @@ -10,8 +8,6 @@ export const DB_USER = process.env.DB_USER || "beep";

export const DB_URL = `postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_DATABASE}`;

export const DB_CA = process.env.DB_CA;

export const REDIS_HOST = process.env.REDIS_HOST || "localhost";

export const REDIS_PASSWROD = process.env.REDIS_PASSWORD;
Expand Down
10 changes: 2 additions & 8 deletions api/src/utils/db.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { DB_CA, DB_HOST, DB_URL } from "./constants";
import { DB_HOST, DB_URL, ENVIRONMENT } from "./constants";
import * as schema from '../../drizzle/schema';

function getOptions() {
if (DB_HOST.includes('neon')) {
if (DB_HOST.includes('neon') || ENVIRONMENT === 'production') {
return { ssl: 'require' as const };
}

if (DB_CA) {
return {
ssl: { ca: DB_CA }
};
}

return undefined
}

Expand Down
4 changes: 1 addition & 3 deletions app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { trpc, queryClient, trpcClient, basicTrpcClient } from './utils/trpc';
import { QueryClientProvider } from '@tanstack/react-query';
import { isWeb } from "./utils/constants";
import "./global.css";
import { useAppState } from "./utils/useAppState";

if (!isWeb) {
Notifications.setNotificationCategoryAsync(
Expand Down Expand Up @@ -76,15 +75,14 @@ setupPurchase();
function Beep() {
const colorScheme = useColorScheme();
const utils = trpc.useUtils();
const appState = useAppState();
const { data: user, isLoading } = trpc.user.me.useQuery(undefined, {
retry: false,
});

useAutoUpdate();

trpc.user.updates.useSubscription(undefined, {
enabled: user !== undefined && appState === 'active',
enabled: user !== undefined,
onData(user) {
utils.user.me.setData(undefined, user);
}
Expand Down
12 changes: 6 additions & 6 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.13.0",
"main": "index.js",
"scripts": {
"dev": "npx tailwindcss -i ./global.css -o ./node_modules/.cache/nativewind/global.css.web.css && EXPO_USE_FAST_RESOLVER=1 expo start --dev-client --web",
"dev": "EXPO_USE_FAST_RESOLVER=1 expo start --dev-client --web",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
Expand All @@ -19,9 +19,9 @@
"@react-navigation/native-stack": "next",
"@sentry/react-native": "5.22.2",
"@tanstack/react-query": "^5.52.0",
"@trpc/client": "11.0.0-rc.502",
"@trpc/react-query": "11.0.0-rc.502",
"car-info": "^0.1.7",
"@trpc/client": "11.0.0-rc.528",
"@trpc/react-query": "11.0.0-rc.528",
"car-info": "0.1.8",
"class-variance-authority": "^0.7.0",
"expo": "51.0.28",
"expo-application": "^5.9.1",
Expand All @@ -37,7 +37,7 @@
"expo-status-bar": "~1.12.1",
"expo-task-manager": "~11.8.1",
"expo-updates": "~0.25.11",
"nativewind": "4.0.36",
"nativewind": "4.1.10",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.51.3",
Expand All @@ -64,7 +64,7 @@
"@types/react": "~18.2.79",
"@types/react-dom": "~18.2.25",
"babel-preset-expo": "^11.0.5",
"typescript": "^5.3.3"
"typescript": "^5.6.2"
},
"private": true,
"volta": {
Expand Down
4 changes: 1 addition & 3 deletions app/routes/beep/StartBeeping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view
import { basicTrpcClient, trpc } from "@/utils/trpc";
import { TRPCClientError } from "@trpc/client";
import { PremiumBanner } from "./PremiumBanner";
import { useAppState } from "@/utils/useAppState";

export const LOCATION_TRACKING = "location-tracking";

export function StartBeepingScreen() {
const { user } = useUser();
const navigation = useNavigation();
const appState = useAppState();

const [isBeeping, setIsBeeping] = useState(user?.isBeeping);
const [singlesRate, setSinglesRate] = useState<string>(
Expand All @@ -48,7 +46,7 @@ export function StartBeepingScreen() {
onData(data) {
utils.beeper.queue.setData(undefined, data);
},
enabled: user && user.isBeeping && appState === 'active',
enabled: user && user.isBeeping,
})

const { mutateAsync: updateBeepSettings } = trpc.user.edit.useMutation({
Expand Down
28 changes: 12 additions & 16 deletions app/routes/cars/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
export const colors = [
"red",
"green",
"blue",
"purple",
"black",
"gray",
"pink",
"white",
"orange",
"tan",
"brown",
"silver",
"Red",
"Green",
"Blue",
"Purple",
"Black",
"Gray",
"Pink",
"White",
"Orange",
"Tan",
"Brown",
"Silver",
];

export function capitalize(value: string) {
return value.charAt(0).toUpperCase() + value.slice(1);
}

export const years = Array.from({ length: 50 }, (_, i) =>
String(new Date().getFullYear() + 1 - i)
);
4 changes: 1 addition & 3 deletions app/routes/ride/BeepersMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { useLocation } from "../../utils/useLocation";
import { type Region } from "react-native-maps";
import { BeeperMarker } from "../../components/Marker";
import { trpc } from "@/utils/trpc";
import { useAppState } from "@/utils/useAppState";

export function BeepersMap() {
const { location } = useLocation();
const utils = trpc.useUtils();
const appState = useAppState();

const input = {
latitude: location?.coords.latitude ?? 0,
Expand All @@ -26,7 +24,7 @@ export function BeepersMap() {
trpc.rider.beepersLocations.useSubscription(
input,
{
enabled: location !== undefined && appState === 'active',
enabled: location !== undefined,
onData(locationUpdate) {
console.log(locationUpdate)
utils.rider.beepersNearMe.setData(input, (prev) => {
Expand Down
7 changes: 2 additions & 5 deletions app/routes/ride/FindBeep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ import { BeeperMarker } from "../../components/Marker";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { StaticScreenProps, useNavigation } from "@react-navigation/native";
import { RouterInput, trpc } from "@/utils/trpc";
import { useAppState } from "@/utils/useAppState";

type Props = StaticScreenProps<{ origin?: string, destination?: string, groupSize?: string } | undefined>;

export function MainFindBeepScreen(props: Props) {
const { user } = useUser();
const { navigate } = useNavigation();

const appState = useAppState();

const utils = trpc.useUtils();
const { data: beep } = trpc.rider.currentRide.useQuery();

Expand All @@ -57,11 +54,11 @@ export function MainFindBeepScreen(props: Props) {
onData(data) {
utils.rider.currentRide.setData(undefined, data);
},
enabled: Boolean(beep) && appState === 'active'
enabled: Boolean(beep)
});

trpc.rider.beeperLocationUpdates.useSubscription(beep?.beeper.id ?? '', {
enabled: isAcceptedBeep && appState === 'active',
enabled: isAcceptedBeep,
onData(updatedLocation) {
utils.rider.currentRide.setData(undefined, (prev) => {
if (!prev) {
Expand Down
6 changes: 3 additions & 3 deletions app/utils/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ function getLocalIP() {
try {
return Constants.experienceUrl.split("//")[1].split(":")[0];
} catch (error) {
return "192.168.1.65";
return "10.0.0.77";
}
}

const ip = getLocalIP();

const wsUrl = __DEV__
? `ws://${ip}:3000`
: "wss://apinext.ridebeep.app";
: "wss://api.ridebeep.app";
const url = __DEV__
? `http://${ip}:3000`
: "https://apinext.ridebeep.app";
: "https://api.ridebeep.app";

export async function getAuthToken() {
const tokens = await AsyncStorage.getItem("auth");
Expand Down
18 changes: 0 additions & 18 deletions app/utils/useAppState.ts

This file was deleted.

6 changes: 3 additions & 3 deletions deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const lkeCluster = new linode.LkeCluster(
"cluster",
{
region: "us-southeast",
k8sVersion: "1.30",
k8sVersion: "1.31",
controlPlane: {
highAvailability: envName === "production",
},
Expand Down Expand Up @@ -74,7 +74,7 @@ const apiDeployment = new k8s.apps.v1.Deployment(
},
spec: {
selector: { matchLabels: { app: apiAppName } },
replicas: 10,
replicas: 5,
template: {
metadata: { labels: { app: apiAppName } },
spec: {
Expand Down Expand Up @@ -130,7 +130,7 @@ const apiService = new k8s.core.v1.Service(
annotations: {
['service.beta.kubernetes.io/linode-loadbalancer-default-protocol']: 'https',
['service.beta.kubernetes.io/linode-loadbalancer-check-type']: 'connection',
['service.beta.kubernetes.io/linode-loadbalancer-port-443']: '{ "tls-secret-name": "cert", "protocol": "https" }'
['service.beta.kubernetes.io/linode-loadbalancer-port-443']: `{ "tls-secret-name": "cert", "protocol": "https" }`
}
},
spec: {
Expand Down
2 changes: 1 addition & 1 deletion deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "index.ts",
"devDependencies": {
"@types/node": "^18",
"typescript": "^5.0.0"
"typescript": "^5.6.2"
},
"dependencies": {
"@pulumi/docker": "^4.5.4",
Expand Down
Loading

0 comments on commit 980501d

Please sign in to comment.