8000 fix: local docker updates and type fixes by seanmalbert · Pull Request #4827 · bloom-housing/bloom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: local docker updates and type fixes #4827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ If you don't have yarn installed, you can install homebrew with [these instructi

Configuration of each app and service is read from environment variables. There is an `.env.template` file in `sites/public`, `sites/partners`, and `api` that must be copied to an `.env` at the same level. Some keys are secret and are internally available. The template files include default values and descriptions of each variable.

### Running a local test server

The following steps work only if all of the [environment variable](#3-local-environment-variables) are setup as well as the steps outlined in [api/README](https://github.com/bloom-housing/bloom/blob/main/api/README.md)

Running `yarn dev:all` from root runs 3 processes for both apps and the backend services on 3 different ports:

- 3000 for the public app
- 3001 for the partners app
- 3100 for the api

You can also run each process individually from separate terminals with the following command in each directory: `yarn dev`.

### Running via docker

The application can also run via docker. Those instructions can be found in the [docker](https://github.com/bloom-housing/bloom/blob/main/docker.md) instructions

### VSCode Extensions

If you use VSCode, these are some recommended extensions.
Expand All @@ -68,16 +84,6 @@ The [CSS variable autocomplete plugin](https://marketplace.visualstudio.com/item

The [CSS module autocomplete plugin](https://marketplace.visualstudio.com/items?itemName=clinyong.vscode-css-modules) which provides autocomplete for CSS module files.

### Running a local test server

Running `yarn dev:all` from root runs 3 processes for both apps and the backend services on 3 different ports:

- 3000 for the public app
- 3001 for the partners app
- 3100 for the api

You can also run each process individually from separate terminals with the following command in each directory: `yarn dev`.

### Bloom UIC development

Because Bloom's ui-components package is a separate open source repository, developing in Bloom while concurrently iterating in ui-components requires linking the folders with the following steps:
Expand Down
30 changes: 10 additions & 20 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
FROM node:18.19

# Base image
FROM node:18
RUN apt-get update
RUN apt-get install -y postgresql-client \
&& rm -rf /var/lib/apt/lists/*

# Create working directory
WORKDIR /usr/src/api

# Copy package.json
COPY package.json ./
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Copy yarn.lcok
COPY yarn.lock ./

# run yarn install
RUN yarn install

# Copy source code into docker image
COPY . .

# Copy .env
COPY .env ./

# run build commands
RUN yarn prisma generate
RUN yarn build

# Expose port 3100 for api
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

EXPOSE 3100
ENTRYPOINT ["./entrypoint.sh"]

# Start api
CMD ["yarn", "dev"]
44 changes: 44 additions & 0 deletions api/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
set -e

DB_HOST="${DB_HOST:-db}"
DB_PORT="${DB_PORT:-5432}"
DB_USER="${DB_USER:-postgres}"
DB_PASS="${DB_PASSWORD:-postgres}"
DB_NAME="bloom_prisma"

echo "⏳ Waiting for Postgres at ${DB_HOST}:${DB_PORT}..."
until pg_isready -h "$DB_HOST" -p "$DB_PORT"; do
sleep 1
done

echo "✅ Postgres is up"

if [ "$RESET_DB" = "true" ]; then
echo "🔄 Resetting database..."

export PGPASSWORD="$DB_PASS"

# Drop & recreate
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -c "DROP DATABASE IF EXISTS ${DB_NAME} WITH (FORCE);"
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -c "CREATE DATABASE ${DB_NAME};"

# Enable uuid‑ossp
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" \
-c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
fi

echo "⏳ Running migrations..."
yarn db:migration:run

if [ "$RUN_SEED" = "true" ]; then
# Default to 'staging' if SEED_ENV not set
SEED_ENV="${SEED_ENV:-staging}"
echo "🌱 Seeding database (env=${SEED_ENV}, jurisdiction=${JURISDICTION_NAME})..."
# this resolves to yarn db:seed:staging -- --environment staging --jurisdictionName $JURISDICTION_NAME
yarn db:seed:"$SEED_ENV" -- --environment "$SEED_ENV" --jurisdictionName "$JURISDICTION_NAME"
fi

echo "🚀 Starting API"
exec yarn dev

4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^7.4.2",
"@nestjs/throttler": "^5.1.2",
"@prisma/client": "^5.0.0",
"@prisma/client": "^5.7.1",
"@sendgrid/helpers": "^8.0.0",
"@sendgrid/mail": "7.7.0",
"@turf/boolean-point-in-polygon": "6.5.0",
Expand Down Expand Up @@ -77,7 +77,7 @@
"passport": "~0.6.0",
"passport-jwt": "~4.0.1",
"passport-local": "~1.0.0",
"prisma": "^5.0.0",
"prisma": "^5.7.1",
"qs": "~6.11.2",
"reflect-metadata": "~0.1.13",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/application-flagged-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
{ status: { not: 'active' } },
],
}
: undefined,
: {},
],
},
});
Expand Down
6 changes: 3 additions & 3 deletions api/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class AuthService {
async confirmUser(dto: Confirm, res?: Response): Promise<SuccessDTO> {
const token = verify(dto.token, process.env.APP_SECRET) as IdAndEmail;

let user = await this.userService.findUserOrError({ userId: token.id });
const user = await this.userService.findUserOrError({ userId: token.id });

if (user.confirmationToken !== dto.token) {
throw new BadRequestException(
Expand All @@ -378,14 +378,14 @@ export class AuthService {
data.email = token.email;
}

user = await this.prisma.userAccounts.update({
const updatedUser = await this.prisma.userAccounts.update({
data,
where: {
id: user.id,
},
});

return await this.setCredentials(res, mapTo(User, user));
return await this.setCredentials(res, mapTo(User, updatedUser));
}

/*
Expand Down
49 changes: 38 additions & 11 deletions api/src/utilities/model-fields.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
import { Prisma } from '@prisma/client';

export const getModelFields = (modelName: string) => {
return Prisma.dmmf.datamodel.models.filter(
(model) => model.name === modelName,
)[0].fields;
};
/**
* A simplified, exportable subset of Prisma's DMMF field definition.
*/
export interface ModelField {
/** The name of the field on the model */
name: string;
/** Whether this field is the primary identifier */
isId: boolean;
/** The Prisma scalar type of the field (e.g. "String", "Int", etc.) */
type: string;
}

export const fillModelStringFields = (
/**
* Get the DMMF field metadata for a given model, cast to our exportable interface.
* @param modelName The name of the Prisma model (as defined in schema.prisma)
* @returns Array of ModelField objects
*/
export function getModelFields(modelName: string): ModelField[] {
const model = Prisma.dmmf.datamodel.models.find((m) => m.name === modelName);
if (!model) {
throw new Error(`Model '${modelName}' not found in Prisma DMMF.`);
}
// Cast the internal field definitions to our simplified, exportable shape
return model.fields as unknown as ModelField[];
}

/**
* Create an object with only the string-based fields (excluding IDs) for a model.
* Useful for seeding or generating partial objects from input data.
* @param modelName The Prisma model name
* @param data A record of input values keyed by field name
* @returns A record containing each non-ID string field, defaulting to null if missing
*/
export function fillModelStringFields(
modelName: string,
data: Record<string, string | null>,
) => {
data: Record<string, string>,
): Record<string, string | null> {
return Object.fromEntries(
getModelFields(modelName)
.filter((field) => field.isId === false && field.type === 'String')
.map((field) => [field.name, data[field.name] || null]),
.filter((field) => !field.isId && field.type === 'String')
.map((field) => [field.name, (data[field.name] as string) || null]),
);
};
}
2 changes: 1 addition & 1 deletion api/test/integration/application-flagged-set.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Application flagged set Controller Tests', () => {
birthYear: nameIndicator,
},
listingId: listing,
householdMember: [householdMember],
householdMember: householdMember ? [householdMember] : undefined,
}),
include: {
applicant: true,
Expand Down
2 changes: 1 addition & 1 deletion api/test/integration/permission-tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ export const createComplexApplication = async (
birthYear: nameAndDOBIndicator,
},
listingId: listing,
householdMember: [householdMember],
householdMember: householdMember ? [householdMember] : undefined,
}),
include: {
applicant: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,7 @@ describe('Testing application flagged set service', () => {
afsLastRunAt: true,
},
where: {
id: undefined,
lastApplicationUpdateAt: {
not: null,
},
Expand All @@ -2550,6 +2551,7 @@ describe('Testing application flagged set service', () => {
},
],
},
{},
],
},
});
Expand Down
53 changes: 49 additions & 4 deletions api/test/unit/utilities/model-fields.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,74 @@
import { randomUUID } from 'node:crypto';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: everywhere else we import, it's just from 'crypto'

import {
fillModelStringFields,
getModelFields,
} from '../../../src/utilities/model-fields';
describe('Testing access to model fields', () => {
describe('Testing getModelFields', () => {
it('should return schema information on model fields', () => {
expect(getModelFields('ListingNeighborhoodAmenities')[0]).toMatchObject({
// there are more properties than this, we'll just test a few:
const ListingNeighborhoodAmenities = getModelFields(
'ListingNeighborhoodAmenities',
);
// ID field
expect(ListingNeighborhoodAmenities[0]).toMatchObject({
kind: 'scalar',
name: 'id',
type: 'String',
hasDefaultValue: true,
isGenerated: false,
isId: true,
isList: false,
isReadOnly: false,
isRequired: true,
isUnique: false,
isUpdatedAt: false,
});
// Non-ID field
expect(ListingNeighborhoodAmenities[1]).toMatchObject({
kind: 'scalar',
name: 'createdAt',
type: 'DateTime',
hasDefaultValue: true,
isGenerated: false,
isId: false,
isList: false,
isReadOnly: false,
isRequired: true,
isUnique: false,
isUpdatedAt: false,
});
expect(ListingNeighborhoodAmenities[3]).toMatchObject({
kind: 'scalar',
name: 'groceryStores',
type: 'String',
hasDefaultValue: false,
isGenerated: false,
isId: false,
isList: false,
isReadOnly: false,
isRequired: false,
isUnique: false,
isUpdatedAt: false,
});

expect(getModelFields('Units')).toHaveLength(30);
});
});
describe('Testing fillModelStringFields', () => {
it("should fill all the fields which weren't filled out with null", () => {
expect(
fillModelStringFields('ListingNeighborhoodAmenities', {
id: randomUUID(), // id should be filtered out
schools: 'Schools',
pharmacies: 'Pharmacies',
}),
).toMatchObject({
// there are more properties than this, we'll just test a few:
).toEqual({
schools: 'Schools',
healthCareResources: null,
groceryStores: null,
parksAndCommunityCenters: null,
pharmacies: 'Pharmacies',
publicTransportation: null,
});
});
});
Expand Down
Loading
0