summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/i
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-13 01:43:22 +0900
committerGitHub <noreply@github.com>2019-04-13 01:43:22 +0900
commit987168b863c52d0548050ffbac569782bb9a8cef (patch)
treec9aa2243dcdcbd044688d201a51c601574bff259 /src/server/api/endpoints/i
parentFix bug (diff)
downloadsharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.gz
sharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.bz2
sharkey-987168b863c52d0548050ffbac569782bb9a8cef.zip
strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
Diffstat (limited to 'src/server/api/endpoints/i')
-rw-r--r--src/server/api/endpoints/i/2fa/done.ts3
-rw-r--r--src/server/api/endpoints/i/2fa/register.ts5
-rw-r--r--src/server/api/endpoints/i/2fa/unregister.ts5
-rw-r--r--src/server/api/endpoints/i/authorized-apps.ts2
-rw-r--r--src/server/api/endpoints/i/change-password.ts5
-rw-r--r--src/server/api/endpoints/i/delete-account.ts5
-rw-r--r--src/server/api/endpoints/i/favorites.ts2
-rw-r--r--src/server/api/endpoints/i/notifications.ts6
-rw-r--r--src/server/api/endpoints/i/regenerate-token.ts5
-rw-r--r--src/server/api/endpoints/i/signin-history.ts2
-rw-r--r--src/server/api/endpoints/i/update-email.ts5
-rw-r--r--src/server/api/endpoints/i/update.ts6
12 files changed, 29 insertions, 22 deletions
diff --git a/src/server/api/endpoints/i/2fa/done.ts b/src/server/api/endpoints/i/2fa/done.ts
index edc7cefd26..e23678dcbb 100644
--- a/src/server/api/endpoints/i/2fa/done.ts
+++ b/src/server/api/endpoints/i/2fa/done.ts
@@ -2,6 +2,7 @@ import $ from 'cafy';
import * as speakeasy from 'speakeasy';
import define from '../../../define';
import { UserProfiles } from '../../../../../models';
+import { ensure } from '../../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -18,7 +19,7 @@ export const meta = {
export default define(meta, async (ps, user) => {
const token = ps.token.replace(/\s/g, '');
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
if (profile.twoFactorTempSecret == null) {
throw new Error('二段階認証の設定が開始されていません');
diff --git a/src/server/api/endpoints/i/2fa/register.ts b/src/server/api/endpoints/i/2fa/register.ts
index db9a2fe944..76d79b3a49 100644
--- a/src/server/api/endpoints/i/2fa/register.ts
+++ b/src/server/api/endpoints/i/2fa/register.ts
@@ -5,6 +5,7 @@ import * as QRCode from 'qrcode';
import config from '../../../../../config';
import define from '../../../define';
import { UserProfiles } from '../../../../../models';
+import { ensure } from '../../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -19,10 +20,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.password, profile.password);
+ const same = await bcrypt.compare(ps.password, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/2fa/unregister.ts b/src/server/api/endpoints/i/2fa/unregister.ts
index fa25b74391..9c7857e7ef 100644
--- a/src/server/api/endpoints/i/2fa/unregister.ts
+++ b/src/server/api/endpoints/i/2fa/unregister.ts
@@ -2,6 +2,7 @@ import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../../define';
import { UserProfiles } from '../../../../../models';
+import { ensure } from '../../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -16,10 +17,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.password, profile.password);
+ const same = await bcrypt.compare(ps.password, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/authorized-apps.ts b/src/server/api/endpoints/i/authorized-apps.ts
index ebf04fcb58..3e9fea19e2 100644
--- a/src/server/api/endpoints/i/authorized-apps.ts
+++ b/src/server/api/endpoints/i/authorized-apps.ts
@@ -31,7 +31,7 @@ export default define(meta, async (ps, user) => {
where: {
userId: user.id
},
- take: ps.limit,
+ take: ps.limit!,
skip: ps.offset,
order: {
id: ps.sort == 'asc' ? 1 : -1
diff --git a/src/server/api/endpoints/i/change-password.ts b/src/server/api/endpoints/i/change-password.ts
index d0e0695e18..0dda125b9c 100644
--- a/src/server/api/endpoints/i/change-password.ts
+++ b/src/server/api/endpoints/i/change-password.ts
@@ -2,6 +2,7 @@ import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../define';
import { UserProfiles } from '../../../../models';
+import { ensure } from '../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -20,10 +21,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.currentPassword, profile.password);
+ const same = await bcrypt.compare(ps.currentPassword, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/delete-account.ts b/src/server/api/endpoints/i/delete-account.ts
index 7ef7aa5fac..389d0b3212 100644
--- a/src/server/api/endpoints/i/delete-account.ts
+++ b/src/server/api/endpoints/i/delete-account.ts
@@ -2,6 +2,7 @@ import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../define';
import { Users, UserProfiles } from '../../../../models';
+import { ensure } from '../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -16,10 +17,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.password, profile.password);
+ const same = await bcrypt.compare(ps.password, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts
index d2d149b2d1..2c25250bea 100644
--- a/src/server/api/endpoints/i/favorites.ts
+++ b/src/server/api/endpoints/i/favorites.ts
@@ -38,7 +38,7 @@ export default define(meta, async (ps, user) => {
.leftJoinAndSelect('favorite.note', 'note');
const favorites = await query
- .take(ps.limit)
+ .take(ps.limit!)
.getMany();
return await NoteFavorites.packMany(favorites, user);
diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts
index 9b016e0a2d..56074c9d00 100644
--- a/src/server/api/endpoints/i/notifications.ts
+++ b/src/server/api/endpoints/i/notifications.ts
@@ -81,13 +81,13 @@ export default define(meta, async (ps, user) => {
query.setParameters(followingQuery.getParameters());
}
- if (ps.includeTypes.length > 0) {
+ if (ps.includeTypes!.length > 0) {
query.andWhere(`notification.type IN (:...includeTypes)`, { includeTypes: ps.includeTypes });
- } else if (ps.excludeTypes.length > 0) {
+ } else if (ps.excludeTypes!.length > 0) {
query.andWhere(`notification.type NOT IN (:...excludeTypes)`, { excludeTypes: ps.excludeTypes });
}
- const notifications = await query.take(ps.limit).getMany();
+ const notifications = await query.take(ps.limit!).getMany();
// Mark all as read
if (notifications.length > 0 && ps.markAsRead) {
diff --git a/src/server/api/endpoints/i/regenerate-token.ts b/src/server/api/endpoints/i/regenerate-token.ts
index ec53bca979..56c0362c88 100644
--- a/src/server/api/endpoints/i/regenerate-token.ts
+++ b/src/server/api/endpoints/i/regenerate-token.ts
@@ -4,6 +4,7 @@ import { publishMainStream } from '../../../../services/stream';
import generateUserToken from '../../common/generate-native-user-token';
import define from '../../define';
import { Users, UserProfiles } from '../../../../models';
+import { ensure } from '../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -18,10 +19,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.password, profile.password);
+ const same = await bcrypt.compare(ps.password, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/signin-history.ts b/src/server/api/endpoints/i/signin-history.ts
index e9ae19d734..74648951fd 100644
--- a/src/server/api/endpoints/i/signin-history.ts
+++ b/src/server/api/endpoints/i/signin-history.ts
@@ -29,7 +29,7 @@ export default define(meta, async (ps, user) => {
const query = makePaginationQuery(Signins.createQueryBuilder('signin'), ps.sinceId, ps.untilId)
.andWhere(`signin.userId = :meId`, { meId: user.id });
- const history = await query.take(ps.limit).getMany();
+ const history = await query.take(ps.limit!).getMany();
return await Promise.all(history.map(record => Signins.pack(record)));
});
diff --git a/src/server/api/endpoints/i/update-email.ts b/src/server/api/endpoints/i/update-email.ts
index d98f0d753e..8b05f3c8cb 100644
--- a/src/server/api/endpoints/i/update-email.ts
+++ b/src/server/api/endpoints/i/update-email.ts
@@ -9,6 +9,7 @@ import * as ms from 'ms';
import * as bcrypt from 'bcryptjs';
import { apiLogger } from '../../logger';
import { Users, UserProfiles } from '../../../../models';
+import { ensure } from '../../../../prelude/ensure';
export const meta = {
requireCredential: true,
@@ -32,10 +33,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id });
+ const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
// Compare password
- const same = await bcrypt.compare(ps.password, profile.password);
+ const same = await bcrypt.compare(ps.password, profile.password!);
if (!same) {
throw new Error('incorrect password');
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index 3cb514d939..d06ab621c6 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -206,13 +206,13 @@ export default define(meta, async (ps, user, app) => {
if (updates.name != null) {
const tokens = parsePlain(updates.name);
- emojis = emojis.concat(extractEmojis(tokens));
+ emojis = emojis.concat(extractEmojis(tokens!));
}
if (profile.description != null) {
const tokens = parse(profile.description);
- emojis = emojis.concat(extractEmojis(tokens));
- tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
+ emojis = emojis.concat(extractEmojis(tokens!));
+ tags = extractHashtags(tokens!).map(tag => tag.toLowerCase());
}
updates.emojis = emojis;