Skip to content

Commit

Permalink
refactor: Create monorepo with ui and server
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Ramirez authored and Tony Ramirez committed Nov 25, 2024
1 parent c7b9038 commit 9f106aa
Show file tree
Hide file tree
Showing 1,076 changed files with 151,506 additions and 21,825 deletions.
31 changes: 31 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#######################
#REQUIRED TO RUN UI
#######################

VITE_CLIENT_URL=http://localhost:5173
VITE_SERVER_URL=http://localhost:9094

VITE_GOOGLE_CLIENT_ID=GOOGLE_CLIENT_ID_THAT_MUST_MATCH_SERVER_GOOGLE_LOGIN_CLIENT_ID


#######################
#REQUIRED TO RUN SERVER
#######################

# Look over the /config/server.config.js file for more information on the environment variables.
# These are just the environment variables required to run the server.

ENVIRONMENT=development
DATABASE_URL=postgresql://postgres:password123@localhost:5432/mydb?schema=public
PORT=9094
SERVER_URL=http://localhost:9094

# A long random string
AUTH_JWT_SECRET=

# A long random string
APP_OAUTH_CALLBACK_STATE_SECRET=

# A 256 bit encryption key (32 characters)
CRYPTO_ENCRYPTION_KEY=
41 changes: 0 additions & 41 deletions .github/workflows/ci.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ tmp
# dependencies
node_modules

# Secrets
**/*.env

# IDEs and editors
/.idea
.project
Expand Down
3 changes: 3 additions & 0 deletions apps/server-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../eslint.config.js');

module.exports = [...baseConfig];
18 changes: 18 additions & 0 deletions apps/server-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
displayName: 'server-e2e',
preset: '../../jest.preset.js',
globalSetup: '<rootDir>/src/support/global-setup.ts',
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/server-e2e',
};
17 changes: 17 additions & 0 deletions apps/server-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "server-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": ["server"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "apps/server-e2e/jest.config.ts",
"passWithNoTests": true
},
"dependsOn": ["server:build"]
}
}
}
10 changes: 10 additions & 0 deletions apps/server-e2e/src/server/server.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios';

describe('GET /api', () => {
it('should return a message', async () => {
const res = await axios.get(`/api`);

expect(res.status).toBe(200);
expect(res.data).toEqual({ message: 'Hello API' });
});
});
10 changes: 10 additions & 0 deletions apps/server-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string;

module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n');

// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
};
7 changes: 7 additions & 0 deletions apps/server-e2e/src/support/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
console.log(globalThis.__TEARDOWN_MESSAGE__);
};
9 changes: 9 additions & 0 deletions apps/server-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable */
import axios from 'axios';

module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ?? '3000';
axios.defaults.baseURL = `http://${host}:${port}`;
};
13 changes: 13 additions & 0 deletions apps/server-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/server-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
3 changes: 3 additions & 0 deletions apps/server/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../eslint.config.js');

module.exports = [...baseConfig];
10 changes: 10 additions & 0 deletions apps/server/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'server',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/server',
};
8 changes: 8 additions & 0 deletions apps/server/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src/modules",
"compilerOptions": {
"deleteOutDir": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "Company" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,

CONSTRAINT "Company_pkey" PRIMARY KEY ("id")
);
26 changes: 26 additions & 0 deletions apps/server/prisma/migrations/20240211070445_user/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Warnings:
- Added the required column `updatedAt` to the `Company` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Company" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "deletedAt" TIMESTAMP(3),
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"email" VARCHAR(255) NOT NULL,
"name" VARCHAR(100) NOT NULL,
"password" VARCHAR(100),

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE "Company" ALTER COLUMN "createdAt" DROP NOT NULL,
ALTER COLUMN "updatedAt" DROP NOT NULL;

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "createdAt" DROP NOT NULL,
ALTER COLUMN "updatedAt" DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:
- Made the column `createdAt` on table `Company` required. This step will fail if there are existing NULL values in that column.
- Made the column `updatedAt` on table `Company` required. This step will fail if there are existing NULL values in that column.
- Made the column `createdAt` on table `User` required. This step will fail if there are existing NULL values in that column.
- Made the column `updatedAt` on table `User` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Company" ALTER COLUMN "createdAt" SET NOT NULL,
ALTER COLUMN "updatedAt" SET NOT NULL;

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "createdAt" SET NOT NULL,
ALTER COLUMN "updatedAt" SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "emailVerifiedAt" TIMESTAMP(3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Warnings:
- You are about to alter the column `name` on the `Company` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(100)`.
*/
-- CreateEnum
CREATE TYPE "CompanyUserRole" AS ENUM ('ADMIN');

-- AlterTable
ALTER TABLE "Company" ALTER COLUMN "name" SET DATA TYPE VARCHAR(100);

-- AlterTable
ALTER TABLE "User" ADD COLUMN "FK_organizationId" TEXT,
ADD COLUMN "rootProfileImageUrl" VARCHAR(255);

-- CreateTable
CREATE TABLE "CompanyUser" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"email" VARCHAR(255) NOT NULL,
"emailVerifiedAt" TIMESTAMP(3),
"name" VARCHAR(100) NOT NULL,
"password" VARCHAR(100),
"profileImageUrl" VARCHAR(255),
"roles" "CompanyUserRole"[],
"FK_userId" TEXT NOT NULL,
"FK_companyId" TEXT NOT NULL,

CONSTRAINT "CompanyUser_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CompanyLocation" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"name" VARCHAR(100) NOT NULL,
"coordinates" JSONB,
"FK_companyId" TEXT NOT NULL,

CONSTRAINT "CompanyLocation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CompanyLocationAddress" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
"street1" VARCHAR(100) NOT NULL,
"street2" VARCHAR(100),
"city" VARCHAR(100) NOT NULL,
"state" VARCHAR(100) NOT NULL,
"zip" VARCHAR(100) NOT NULL,
"country" VARCHAR(100) NOT NULL,
"FK_location" TEXT NOT NULL,

CONSTRAINT "CompanyLocationAddress_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "CompanyUser_email_key" ON "CompanyUser"("email");

-- CreateIndex
CREATE UNIQUE INDEX "CompanyLocationAddress_FK_location_key" ON "CompanyLocationAddress"("FK_location");

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_FK_organizationId_fkey" FOREIGN KEY ("FK_organizationId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CompanyUser" ADD CONSTRAINT "CompanyUser_FK_userId_fkey" FOREIGN KEY ("FK_userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CompanyUser" ADD CONSTRAINT "CompanyUser_FK_companyId_fkey" FOREIGN KEY ("FK_companyId") REFERENCES "Company"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CompanyLocation" ADD CONSTRAINT "CompanyLocation_FK_companyId_fkey" FOREIGN KEY ("FK_companyId") REFERENCES "Company"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CompanyLocationAddress" ADD CONSTRAINT "CompanyLocationAddress_FK_location_fkey" FOREIGN KEY ("FK_location") REFERENCES "CompanyLocation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Warnings:
- You are about to drop the column `deletedAt` on the `Company` table. All the data in the column will be lost.
- You are about to drop the column `deletedAt` on the `CompanyLocation` table. All the data in the column will be lost.
- You are about to drop the column `deletedAt` on the `CompanyLocationAddress` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "CompanyLocationAddress" DROP CONSTRAINT "CompanyLocationAddress_FK_location_fkey";

-- AlterTable
ALTER TABLE "Company" DROP COLUMN "deletedAt";

-- AlterTable
ALTER TABLE "CompanyLocation" DROP COLUMN "deletedAt";

-- AlterTable
ALTER TABLE "CompanyLocationAddress" DROP COLUMN "deletedAt";

-- AddForeignKey
ALTER TABLE "CompanyLocationAddress" ADD CONSTRAINT "CompanyLocationAddress_FK_location_fkey" FOREIGN KEY ("FK_location") REFERENCES "CompanyLocation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Loading

0 comments on commit 9f106aa

Please sign in to comment.