Utilize ?. operator and set TypeScript target
This commit is contained in:
1 parent
ca83704958
commit
c3c7ab72b2
19 files changed
+55
-77
No files matched your search
@@ -200,7 +200,7 @@ export function authLocal(
|
||||
return new Promise((resolve, reject) => {
|
||||
const users = getUsers(snapshot);
|
||||
const user = users[username];
|
||||
if (!user || !user.password) return void resolve(null);
|
||||
if (!user?.password) return void resolve(null);
|
||||
hashPassword(password, user.salt)
|
||||
.then((hash) => {
|
||||
if (hash === user.password) resolve(true);
|
||||
|
||||
+2
-2
@@ -573,12 +573,12 @@ router.post("/devices/:id/tasks", async (ctx) => {
|
||||
if (!Array.isArray(exp)) return exp;
|
||||
if (exp[0] === "PARAM") {
|
||||
const p = device[exp[1]];
|
||||
if (p && p.value) return p.value[0];
|
||||
if (p?.value) return p.value[0];
|
||||
} else if (exp[0] === "FUNC") {
|
||||
if (exp[1] === "REMOTE_ADDRESS") {
|
||||
for (const root of ["InternetGatewayDevice", "Device"]) {
|
||||
const p = device[`${root}.ManagementServer.ConnectionRequestURL`];
|
||||
if (p && p.value) return new URL(p.value[0]).hostname;
|
||||
if (p?.value) return new URL(p.value[0]).hostname;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+4
-4
@@ -190,8 +190,8 @@ export async function updateDeviceTags(
|
||||
const collection = db.collection("devices");
|
||||
const object = {};
|
||||
|
||||
if (add && add.length) object["$addToSet"] = { _tags: { $each: add } };
|
||||
if (pull && pull.length) object["$pullAll"] = { _tags: pull };
|
||||
if (add?.length) object["$addToSet"] = { _tags: { $each: add } };
|
||||
if (pull?.length) object["$pullAll"] = { _tags: pull };
|
||||
|
||||
await collection.updateOne({ _id: deviceId }, object);
|
||||
}
|
||||
@@ -242,7 +242,7 @@ export function putProvision(
|
||||
lineOffset: -1,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.stack && err.stack.startsWith(`${id}:`)) {
|
||||
if (err.stack?.startsWith(`${id}:`)) {
|
||||
return Promise.reject(
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`)
|
||||
);
|
||||
@@ -267,7 +267,7 @@ export function putVirtualParameter(
|
||||
lineOffset: -1,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.stack && err.stack.startsWith(`${id}:`)) {
|
||||
if (err.stack?.startsWith(`${id}:`)) {
|
||||
return Promise.reject(
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`)
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user