|
|
|
@ -6,6 +6,7 @@ import globals from "../lib/globals";
|
|
|
|
|
import {InternalEvents} from "../lib/InternalEvents";
|
|
|
|
|
import * as models from "../lib/models";
|
|
|
|
|
import {is} from "../lib/regex";
|
|
|
|
|
import * as yaml from "js-yaml";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the resolvers for the graphql api.
|
|
|
|
@ -121,6 +122,22 @@ export function resolver(req: any, res: any): any {
|
|
|
|
|
return new GraphQLError("No username, email or password given.");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async setUserSettings({settings}: {settings: string}) {
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|
const user = await models.User.findByPk(req.session.userId);
|
|
|
|
|
try {
|
|
|
|
|
user.frontendSettings = yaml.safeLoad(settings);
|
|
|
|
|
await user.save();
|
|
|
|
|
return user.settings;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
res.status(400);
|
|
|
|
|
return new GraphQLError("Invalid settings json.");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
res.status(status.UNAUTHORIZED);
|
|
|
|
|
return new NotLoggedInGqlError();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async vote({postId, type}: { postId: number, type: dataaccess.VoteType }) {
|
|
|
|
|
if (postId && type) {
|
|
|
|
|
if (req.session.userId) {
|
|
|
|
|