Skip to content
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

Fix migrate v7 #25

Open
wants to merge 5 commits into
base: master
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
10 changes: 8 additions & 2 deletions packages/backoffice/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Formio } from "@tsed/react-formio";
import { IfSidebar, Loader, oneOfIsActive, useSidebar } from "@tsed/shared";
import React from "react";
import React, { useEffect } from "react";
import { useSelector } from "react-redux";
import { Route as DefaultRoute, Switch } from "react-router";
import { Route as DefaultRoute, Switch, useHistory } from "react-router";
import { useAuth } from "./auth/useAuth.hook";
import { Config } from "./config";
import { IfHeader } from "./header/header.component";
Expand All @@ -18,10 +19,15 @@ function App() {
const { headerHeight } = Config;
const { isAuth, isActive, auth, onLogout } = useAuth();
const nav = useNav();
const history = useHistory();

const { sidebarOpen, toggleSidebar } = useSidebar();
const size = sidebarOpen ? "64" : "14";

useEffect(() => {
Formio.clearCache();
}, [history.location.pathname]);

if (isActive) {
return <Loader isActive={isActive} />;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/server/coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"statements": 89.68,
"branches": 70.67,
"functions": 79.17,
"lines": 89.27
}
7 changes: 1 addition & 6 deletions packages/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ module.exports = {

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
'branches': 73.56,
'functions': 79.17,
'lines': 89.4,
'statements': 89.79
}
global: require('./coverage.json')
},

// An array of file extensions your modules use
Expand Down
45 changes: 25 additions & 20 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@
},
"dependencies": {
"@octokit/rest": "18.12.0",
"@tsed/ajv": "6.103.2",
"@tsed/async-hook-context": "6.103.2",
"@tsed/common": "6.103.2",
"@tsed/core": "6.103.2",
"@tsed/di": "6.103.2",
"@tsed/exceptions": "6.103.2",
"@tsed/formio": "6.103.2",
"@tsed/json-mapper": "6.103.2",
"@tsed/logger": "6.1.0",
"@tsed/logger-logentries": "6.1.0",
"@tsed/mongoose": "6.103.2",
"@tsed/passport": "6.103.2",
"@tsed/platform-express": "6.103.2",
"@tsed/schema": "6.103.2",
"@tsed/swagger": "6.103.2",
"@tsed/ajv": "7.0.0-rc.3",
"@tsed/common": "7.0.0-rc.3",
"@tsed/core": "7.0.0-rc.3",
"@tsed/di": "7.0.0-rc.3",
"@tsed/exceptions": "7.0.0-rc.3",
"@tsed/formio": "7.0.0-rc.3",
"@tsed/json-mapper": "7.0.0-rc.3",
"@tsed/logger": "6.2.1",
"@tsed/mongoose": "7.0.0-rc.3",
"@tsed/passport": "7.0.0-rc.3",
"@tsed/platform-express": "7.0.0-rc.3",
"@tsed/platform-params": "7.0.0-rc.3",
"@tsed/platform-cache": "7.0.0-rc.3",
"@tsed/platform-exceptions": "7.0.0-rc.3",
"@tsed/platform-response-filter": "7.0.0-rc.3",
"@tsed/platform-middlewares": "7.0.0-rc.3",
"@tsed/platform-log-middleware": "7.0.0-rc.3",
"@tsed/platform-views": "7.0.0-rc.3",
"@tsed/schema": "7.0.0-rc.3",
"@tsed/swagger": "7.0.0-rc.3",
"ajv": "8.10.0",
"body-parser": "1.19.2",
"cache-manager": "3.6.0",
Expand All @@ -58,11 +63,11 @@
"url-parse": "1.5.10"
},
"devDependencies": {
"@tsed/cli-plugin-eslint": "3.1.0",
"@tsed/cli-plugin-jest": "3.1.0",
"@tsed/cli-plugin-mongoose": "3.1.0",
"@tsed/cli-plugin-passport": "3.1.0",
"@tsed/testing-mongoose": "6.103.2",
"@tsed/cli-plugin-eslint": "4.0.0-rc.1",
"@tsed/cli-plugin-jest": "4.0.0-rc.1",
"@tsed/cli-plugin-mongoose": "4.0.0-rc.1",
"@tsed/cli-plugin-passport": "4.0.0-rc.1",
"@tsed/testing-mongoose": "7.0.0-rc.3",
"@types/cache-manager": "3.4.0",
"@types/cache-manager-ioredis": "2.0.2",
"@types/compression": "^1.7.0",
Expand Down
10 changes: 3 additions & 7 deletions packages/server/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "@tsed/ajv";
import "@tsed/async-hook-context";
import {PlatformApplication, Res} from "@tsed/common";
import {Env} from "@tsed/core";
import {Configuration, Inject} from "@tsed/di";
import "@tsed/formio";
import {Logger} from "@tsed/logger";
import "@tsed/mongoose";
import "@tsed/platform-express"; // /!\ keep this import
import "@tsed/platform-cache";
import "@tsed/swagger";
import bodyParser from "body-parser";
import compression from "compression";
Expand All @@ -18,7 +18,7 @@ import {join} from "path";
import send from "send";
import {cacheConfig} from "./config/cache";
import formioConfig from "./config/formio";
import {configureLogger, loggerConfig} from "./config/logger";
import {loggerConfig} from "./config/logger";
import mongooseConfig from "./config/mongoose";
import swaggerConfig from "./config/swagger";
import * as controllers from "./controllers/rest/index";
Expand Down Expand Up @@ -101,7 +101,7 @@ export class Server {
settings: Configuration;

$afterRoutesInit() {
this.app.get("/backoffice/*", (req: any, res: Res) => {
this.app.get("/backoffice/*", (req: any, res: any) => {
res.sendFile(join(backofficeDir, "index.html"));
});
}
Expand All @@ -116,8 +116,4 @@ export class Server {
});
}
}

$onReady() {
configureLogger();
}
}
27 changes: 0 additions & 27 deletions packages/server/src/config/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {isProduction} from "../env";
import {$log} from "@tsed/common";
import "@tsed/logger-logentries";

$log.name = process.env.LOG_NAME || "API";

Expand All @@ -26,29 +25,3 @@ if (isProduction) {
}
});
}

export function configureLogger() {
if (process.env.LOG_ENTRIES_KEY) {
$log.appenders
.set("logentries", {
type: "logentries",
levels: ["info", "debug"],
layout: {
type: "json"
},
options: {
token: process.env.LOG_ENTRIES_KEY
}
})
.set("logentries", {
levels: ["trace", "fatal", "error", "warn"],
type: "logentries",
layout: {
type: "json"
},
options: {
token: process.env.LOG_ENTRIES_KEY
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "@tsed/ajv";
import {PlatformApplication} from "@tsed/common";
import {Configuration, Inject} from "@tsed/di";
import "@tsed/async-hook-context";
import "@tsed/mongoose";
import "@tsed/platform-express"; // /!\ keep this import
import "@tsed/swagger";
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/controllers/rest/github/GithubCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {InjectContext} from "@tsed/async-hook-context";
import {InjectContext} from "@tsed/di";
import {BodyParams, Controller, Get, HeaderParams, Inject, PathParams, PlatformContext, Post, QueryParams} from "@tsed/common";
import {array, boolean, Default, Max, Min, Name, number, object, Returns, string} from "@tsed/schema";
import {GithubWebhookPayload} from "../../../domain/github/GithubWebhookPayload";
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/infra/back/github/GithubClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Octokit} from "@octokit/rest";
import {RequestParameters} from "@octokit/types";
import {InjectContext} from "@tsed/async-hook-context";
import {PlatformContext, UseCache} from "@tsed/common";
import {InjectContext} from "@tsed/di";
import {PlatformContext} from "@tsed/common";
import {UseCache} from "@tsed/platform-cache";
import {Constant, Injectable} from "@tsed/di";
import {Unauthorized} from "@tsed/exceptions";
import {BaseLogClient} from "../http/BaseLogClient";
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/infra/back/http/BaseLogClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InjectContext} from "@tsed/async-hook-context";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import {Opts, PlatformContext} from "@tsed/common";
import {InjectContext} from "@tsed/di";
import {get} from "lodash";
import querystring from "querystring";
import {logToCurl} from "./logToCurl";
Expand Down
11 changes: 4 additions & 7 deletions packages/server/src/infra/back/http/HttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ConverterService, Inject} from "@tsed/common";
import {cleanObject, Type} from "@tsed/core";
import {Injectable} from "@tsed/di";
import {Exception} from "@tsed/exceptions";
import {deserialize, serialize} from "@tsed/json-mapper";
import axios, {AxiosRequestConfig, Method} from "axios";
import {get, omit} from "lodash";
import querystring from "querystring";
Expand All @@ -16,9 +16,6 @@ export interface HttpClientOptions extends AxiosRequestConfig, Record<string, un

@Injectable()
export class HttpClient extends BaseLogClient {
@Inject()
protected mapper: ConverterService;

static getParamsSerializer(params: any) {
return querystring.stringify(cleanObject(params));
}
Expand Down Expand Up @@ -90,8 +87,8 @@ export class HttpClient extends BaseLogClient {
method,
url: endpoint,
...omit(options, ["type", "collectionType", "additionalProperties"]),
params: this.mapper.serialize(options.params),
data: this.mapper.serialize(options.data),
params: serialize(options.params),
data: serialize(options.data),
headers: cleanObject({
"Content-Type": "application/json",
Accept: "application/json",
Expand All @@ -105,7 +102,7 @@ export class HttpClient extends BaseLogClient {

let data = !withHeaders ? result.data : result;

data = this.mapper.deserialize(data, {
data = deserialize(data, {
collectionType,
type,
useAlias: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/infra/back/npm/NpmClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InjectContext} from "@tsed/async-hook-context";
import {PlatformContext, UseCache} from "@tsed/common";
import {Injectable} from "@tsed/di";
import {PlatformContext} from "@tsed/common";
import {UseCache} from "@tsed/platform-cache";
import {Injectable, InjectContext} from "@tsed/di";
import {deserialize} from "@tsed/json-mapper";
import {Method} from "axios";
import url from "url";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UseCache} from "@tsed/common";
import {UseCache} from "@tsed/platform-cache";
import {Injectable} from "@tsed/di";
import {HttpClient} from "../http/HttpClient";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HeaderParams, IMiddleware, Middleware, Req, Res} from "@tsed/common";
import {HeaderParams, MiddlewareMethods, Middleware, Req, Res} from "@tsed/common";

@Middleware()
export class EnsureHttpsMiddleware implements IMiddleware {
export class EnsureHttpsMiddleware implements MiddlewareMethods {
use(@HeaderParams("x-forwarded-proto") protocol: string, @HeaderParams("host") host: string, @Req("url") url: string, @Res() res: Res) {
if (protocol !== "https") {
res.redirect(`https://${host}${url}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class RepositoriesMigration {
this.logger.info("Check repositories migration...");
const mapper = await this.formioDatabase.getFormioMapper();

await this.formioDatabase.createFormIfNotExists(formRepositories as any, async (form) => {
await this.formioDatabase.importFormIfNotExists(formRepositories as any, async (form) => {
this.logger.info('Install "Repositories" form');
const action = mapper.mapToImport({
...formRepositoriesAction,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/migrations/user/UserMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class RepositoriesMigration {
if (form && this.shouldUpdate(form as FormioForm)) {
try {
this.logger.info("Create form definition...");
await this.formioDatabase.saveFormDefinition({...userLoginForm, _id: form._id.toString()} as any);
await this.formioDatabase.importForm({...userLoginForm, _id: form._id.toString()} as any);

const mappedAction = mapper.mapToImport({
...userLoginOAuthAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class WarehouseMigration {
async install() {
this.logger.info("Check warehouse migration...");
const mapper = await this.formioDatabase.getFormioMapper();
await this.formioDatabase.createFormIfNotExists(formPackages as any, async (form) => {

await this.formioDatabase.importFormIfNotExists(formPackages as any, async (form) => {
this.logger.info('Install "NPM packages" form');
await new this.formioDatabase.actionModel(
mapper.mapToImport({
Expand Down
32 changes: 10 additions & 22 deletions packages/server/src/services/FormioRepository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ describe("FormioRepository", () => {
_id: "id"
})
},
saveSubmission: jest.fn().mockImplementation((instance) => instance),
submissionModel: class {
static findOneAndUpdate = jest.fn().mockImplementation(({_id}, instance) => {
return {
_id: _id || "newid",
...instance
};
});
constructor(o: any) {
Object.assign(this, {...o, _id: o._id || "newid"});
}
}
};

Expand All @@ -49,11 +47,7 @@ describe("FormioRepository", () => {
},
form: "id"
});
expect(database.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
{_id: undefined},
{data: {label: "label"}, form: "id"},
{upsert: true, new: true}
);
expect(database.saveSubmission).toHaveBeenCalledWith({_id: "newid", data: {label: "label"}, form: "id"});
});
it("should save submission", async () => {
const database = {
Expand All @@ -62,13 +56,11 @@ describe("FormioRepository", () => {
_id: "id"
})
},
saveSubmission: jest.fn().mockImplementation((instance) => instance),
submissionModel: class {
static findOneAndUpdate = jest.fn().mockImplementation(({_id}, instance) => {
return {
_id: _id || "newid",
...instance
};
});
constructor(o: any) {
Object.assign(this, {...o, _id: o._id || "newid"});
}
}
};

Expand All @@ -93,11 +85,7 @@ describe("FormioRepository", () => {
},
form: "id"
});
expect(database.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
{_id: "id"},
{_id: "id", data: {label: "label"}, form: "id"},
{upsert: true, new: true}
);
expect(database.saveSubmission).toHaveBeenCalledWith({_id: "id", data: {label: "label"}, form: "id"});
});
});
describe("getSubmissions()", () => {
Expand Down
Loading