more logging

This commit is contained in:
lingdocs 2022-09-01 19:40:03 +04:00
parent ef5f0c9444
commit 46d7f45e1a
2 changed files with 12 additions and 8 deletions

View File

@ -18,12 +18,10 @@ app.use(cors({
// origin: "*",
origin: inProd ? /\.lingdocs\.com$/ : "*",
credentials: true,
methods: ["GET","HEAD","PUT","POST","DELETE"],
}));
app.use((req, res, next) => {
// res.append('Access-Control-Allow-Origin', ['*']);
res.append('Access-Control-Allow-Methods', 'GET,HEAD,PUT,POST,DELETE');
res.append("test-header", "cool");
res.append('Access-Control-Allow-Methods', 'GET,HEAD,PUT,POST,DELETE,OPTIONS');
next();
});
if (inProd) app.set('trust proxy', 1);

View File

@ -49,12 +49,18 @@ export async function getAllLingdocsUsers(): Promise<T.LingdocsUser[]> {
}
export async function insertLingdocsUser(user: T.LingdocsUser): Promise<T.LingdocsUser> {
const res = await usersDb.insert(user);
const newUser = processAPIResponse(user, res);
if (!newUser) {
try {
const res = await usersDb.insert(user);
const newUser = processAPIResponse(user, res);
if (!newUser) {
throw new Error("error inserting user");
}
return newUser;
} catch(e) {
console.log("ERROR on insertLingdocsUser", user);
console.log(e);
throw new Error("error inserting user");
}
return newUser;
}
export async function deleteLingdocsUser(uuid: T.UUID): Promise<void> {
@ -104,7 +110,7 @@ export async function updateLingdocsUser(uuid: T.UUID, toUpdate:
): Promise<T.LingdocsUser> {
const user = await getLingdocsUser("userId", uuid);
if (!user) throw new Error("unable to update - user not found " + uuid);
// console.log("inUpdateLingdocsUser", toUpdate);
console.log("inUpdateLingdocsUser", toUpdate);
if ("tests" in toUpdate) {
return await insertLingdocsUser({
...user,