🔧 Fleshing out save and get settings endpoints
This commit is contained in:
@@ -6,17 +6,15 @@ const SettingsScehma = mongoose.Schema({
|
|||||||
client: {
|
client: {
|
||||||
name: String,
|
name: String,
|
||||||
version: String,
|
version: String,
|
||||||
|
airdcppUserSettings: Object,
|
||||||
hostname: String,
|
hostname: String,
|
||||||
port: Number,
|
protocol: String,
|
||||||
https: Boolean,
|
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
hubs: [{
|
hubs: [{}],
|
||||||
|
},
|
||||||
}]
|
},
|
||||||
}
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const Settings = mongoose.model("Settings", SettingsScehma);
|
const Settings = mongoose.model("Settings", SettingsScehma);
|
||||||
export default Settings;
|
export default Settings;
|
||||||
@@ -142,9 +142,7 @@ export default class ApiService extends Service {
|
|||||||
stat.mtime.getTime() ===
|
stat.mtime.getTime() ===
|
||||||
previousPath.mtime.getTime()
|
previousPath.mtime.getTime()
|
||||||
) {
|
) {
|
||||||
logger.info(
|
logger.info("File detected, starting import...");
|
||||||
"File copy complete, starting import..."
|
|
||||||
);
|
|
||||||
const walkedFolders: IFolderData =
|
const walkedFolders: IFolderData =
|
||||||
await broker.call("import.walkFolders", {
|
await broker.call("import.walkFolders", {
|
||||||
basePathToWalk: path,
|
basePathToWalk: path,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "moleculer";
|
} from "moleculer";
|
||||||
import { DbMixin } from "../mixins/db.mixin";
|
import { DbMixin } from "../mixins/db.mixin";
|
||||||
import Settings from "../models/settings.model";
|
import Settings from "../models/settings.model";
|
||||||
|
import { isEmpty } from "lodash";
|
||||||
|
|
||||||
export default class SettingsService extends Service {
|
export default class SettingsService extends Service {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -27,14 +28,46 @@ export default class SettingsService extends Service {
|
|||||||
getSettings: {
|
getSettings: {
|
||||||
rest: "GET /getAllSettings",
|
rest: "GET /getAllSettings",
|
||||||
params: {},
|
params: {},
|
||||||
async handler(ctx: Context<{}>) {},
|
async handler(
|
||||||
|
ctx: Context<{ settingsKey: string }>
|
||||||
|
) {
|
||||||
|
const settings = await Settings.find({});
|
||||||
|
if (isEmpty(settings)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
console.log(settings[0]);
|
||||||
|
return settings[0];
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
saveSettings: {
|
saveSettings: {
|
||||||
rest: "POST /saveSettings",
|
rest: "POST /saveSettings",
|
||||||
params: {},
|
params: {},
|
||||||
async handler(ctx: Context<{}>) {
|
async handler(
|
||||||
|
ctx: Context<{
|
||||||
|
settingsObject: {
|
||||||
|
hostname: string;
|
||||||
|
protocol: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
airdcppUserSettings: object;
|
||||||
|
}>
|
||||||
|
) {
|
||||||
console.log(ctx.params);
|
console.log(ctx.params);
|
||||||
|
const { settingsObject, airdcppUserSettings } =
|
||||||
|
ctx.params;
|
||||||
|
|
||||||
|
const result = await Settings.create({
|
||||||
|
directConnect: {
|
||||||
|
client: {
|
||||||
|
...settingsObject,
|
||||||
|
airdcppUserSettings,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log("ASDASD", result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user