Skip to content

Commit

Permalink
Clean-up and organization
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Hugs committed Aug 21, 2021
1 parent 29a5aaf commit 01edd7b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
11 changes: 8 additions & 3 deletions src/client/scripts/crud/CrudAssociations.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DetailsList, mergeStyles, SelectionMode } from "@fluentui/react";
import { useMemo } from "react";
import { EntityData, PluralizationMap } from "../../../../@types/app/shared";
import { Link } from "../common/Link";
import { usePageData } from "../hooks/usePageData";
Expand All @@ -8,20 +9,24 @@ export const CrudAssociations: React.FC<{}> = () => {
const pluralizationMap = usePageData<PluralizationMap>("pluralizationMap");
//const associations = usePageData<any[]>("associations");
const noBottomMargin = mergeStyles({ marginBottom: 0 });
const associations = useMemo(() => {
const uniqueAssoc = new Set<string>(entity.associations.map(a => a.name));
return [...uniqueAssoc];
}, [entity.associations]);
return (
<div>
<h2 className={noBottomMargin}>{entity.name} associations</h2>
<DetailsList
items={entity.associations}
items={associations}
selectionMode={SelectionMode.none}
compact={true}
columns={[
{
key: "name",
name: "Name",
name: "Model",
minWidth: 175,
maxWidth: 175,
onRender: (item) => <Link href={`/crud/${pluralizationMap.toPlural[item.name]}`}>{item.name}</Link>,
onRender: (item) => <Link href={`/crud/${pluralizationMap.toPlural[item]}`}>{item}</Link>,
},
]}
/>
Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/crud/ModelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const ModelList: React.FC<{}> = () => {
})),
},
];
console.log("Nav render");
return <Nav groups={navLinkGroups} onLinkClick={onLinkClick} />;
};
ModelList.displayName = "ModelList";
42 changes: 3 additions & 39 deletions src/modules/frontend.tsx → src/controllers/CrudController.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import { AppModule } from "@deepkit/app";
import { FrontendService } from "../services/frontend/frontendService";
import { http, httpMiddleware, HttpRequest } from "@deepkit/http";
import { serveStaticListener } from "@deepkit/http";
import { http } from "@deepkit/http";
import { EntitiesService } from "../services/entities/entitiesService";
import { singular } from "pluralize";
import path from "path";
import { CrudService } from "../services/crud/crudService";
import { TheBroomstackDatabase } from "../dataModel/database";
import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import webpack from "webpack";

const webpackConfig = require("../client/webpack.config.js");
const { publicPath } = webpackConfig.output;
const compiler = webpack(webpackConfig);

@http.controller("/")
export class FrontendController {
export class CrudController {
constructor(
protected frontendService: FrontendService,
protected request: HttpRequest,
protected entitiesService: EntitiesService,
protected crudService: CrudService,
protected database: TheBroomstackDatabase
) {}

@(http.GET("").description("Home page"))
async home() {
return this.frontendService.renderAppTemplate({});
}

@(http.GET("crud").description("Crud index"))
async crud() {
return this.frontendService.renderAppTemplate({
Expand All @@ -54,25 +38,5 @@ export class FrontendController {
scripts: ["main.js"],
styleSheets: ["main.css"],
});
// const result = this.entitiesService.getEntity(entityName);
}

// Route for hot module replacement event stream, handled by the webpackHotMiddleware below.
@http.GET("/__webpack_hmr")
async hmr() {}
}

const publicDir = path.resolve(__dirname, "..", "..", "public");
const servePublic = serveStaticListener("/public", publicDir);
export const FrontendModule = new AppModule(
{
controllers: [FrontendController],
providers: [{ provide: FrontendService, scope: "http" }, EntitiesService, CrudService],
listeners: [servePublic],
middlewares: [
httpMiddleware.for(webpackDevMiddleware(compiler, { publicPath: publicPath.Path, writeToDisk: true })),
httpMiddleware.for(webpackHotMiddleware(compiler)),
],
},
"frontend"
);
}
16 changes: 16 additions & 0 deletions src/controllers/FrontendController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FrontendService } from "../services/frontend/frontendService";
import { http } from "@deepkit/http";

@http.controller("/")
export class FrontendController {
constructor(protected frontendService: FrontendService) {}

@(http.GET("").description("Home page"))
async home() {
return this.frontendService.renderAppTemplate({});
}

// Route for hot module replacement event stream, handled by the webpackHotMiddleware below.
@http.GET("/__webpack_hmr")
async hmr() {}
}
12 changes: 6 additions & 6 deletions src/modules/crud.ts → src/modules/CrudModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http, HttpResponse } from "@deepkit/http";
import { getClassSchema, plainToClass, t, ClassSchema } from "@deepkit/type";
import { getObjectKeysSize, ClassType } from "@deepkit/core";
import { http } from "@deepkit/http";
import { getClassSchema, t, ClassSchema } from "@deepkit/type";
import { ClassType } from "@deepkit/core";
import { AppModule } from "@deepkit/app";
import { TheBroomstackDatabase } from "../dataModel/database";

Expand Down Expand Up @@ -169,7 +169,7 @@ function createController(schema: ClassSchema): ClassType {
return this.crudService.delete(schema, deleteOptions);
}

// Should be PATCH
// Should be PATCH
@(http.PUT("").description("Updates " + schema.name))
async update(@t.partial(schema) @http.body() body: any, @http.queries() options: EntityUpdateQueryOptions) {
const patchOptions = {
Expand All @@ -183,8 +183,8 @@ function createController(schema: ClassSchema): ClassType {
return this.crudService.update(schema, patchOptions, body);
}

// Should be PATCH
@(http.PUT(":id").description("Updates " + schema.name))
// Should be PATCH
@(http.PUT(":id").description("Updates " + schema.name))
async updateOne(id: number, @t.partial(schema) @http.body() body: any) {
const patchOptions = {
filter: { [primaryKey.name]: id },
Expand Down
31 changes: 31 additions & 0 deletions src/modules/FrontendModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AppModule } from "@deepkit/app";
import { FrontendService } from "../services/frontend/frontendService";
import { httpMiddleware } from "@deepkit/http";
import { serveStaticListener } from "@deepkit/http";
import { EntitiesService } from "../services/entities/entitiesService";
import path from "path";
import { CrudService } from "../services/crud/crudService";
import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import webpack from "webpack";
import { FrontendController } from "../controllers/FrontendController";
import { CrudController } from "../controllers/CrudController";

const webpackConfig = require("../client/webpack.config.js");
const { publicPath } = webpackConfig.output;
const compiler = webpack(webpackConfig);

const publicDir = path.resolve(__dirname, "..", "..", "public");
const servePublic = serveStaticListener("/public", publicDir);
export const FrontendModule = new AppModule(
{
controllers: [FrontendController, CrudController],
providers: [{ provide: FrontendService, scope: "http" }, EntitiesService, CrudService],
listeners: [servePublic],
middlewares: [
httpMiddleware.for(webpackDevMiddleware(compiler, { publicPath: publicPath.Path, writeToDisk: true })),
httpMiddleware.for(webpackHotMiddleware(compiler)),
],
},
"frontend"
);
File renamed without changes.

0 comments on commit 01edd7b

Please sign in to comment.