diff options
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r-- | server/models/account/account.ts | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index cd6c822f1..d2293a939 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -31,7 +31,8 @@ let load: AccountMethods.Load | |||
31 | let loadApplication: AccountMethods.LoadApplication | 31 | let loadApplication: AccountMethods.LoadApplication |
32 | let loadByUUID: AccountMethods.LoadByUUID | 32 | let loadByUUID: AccountMethods.LoadByUUID |
33 | let loadByUrl: AccountMethods.LoadByUrl | 33 | let loadByUrl: AccountMethods.LoadByUrl |
34 | let loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod | 34 | let loadLocalByName: AccountMethods.LoadLocalByName |
35 | let loadByNameAndHost: AccountMethods.LoadByNameAndHost | ||
35 | let listOwned: AccountMethods.ListOwned | 36 | let listOwned: AccountMethods.ListOwned |
36 | let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi | 37 | let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi |
37 | let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi | 38 | let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi |
@@ -88,7 +89,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes | |||
88 | }, | 89 | }, |
89 | privateKey: { | 90 | privateKey: { |
90 | type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max), | 91 | type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max), |
91 | allowNull: false, | 92 | allowNull: true, |
92 | validate: { | 93 | validate: { |
93 | privateKeyValid: value => { | 94 | privateKeyValid: value => { |
94 | const res = isAccountPrivateKeyValid(value) | 95 | const res = isAccountPrivateKeyValid(value) |
@@ -199,7 +200,8 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes | |||
199 | load, | 200 | load, |
200 | loadByUUID, | 201 | loadByUUID, |
201 | loadByUrl, | 202 | loadByUrl, |
202 | loadLocalAccountByNameAndPod, | 203 | loadLocalByName, |
204 | loadByNameAndHost, | ||
203 | listOwned, | 205 | listOwned, |
204 | listAcceptedFollowerUrlsForApi, | 206 | listAcceptedFollowerUrlsForApi, |
205 | listAcceptedFollowingUrlsForApi, | 207 | listAcceptedFollowingUrlsForApi, |
@@ -330,6 +332,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { | |||
330 | include: [ | 332 | include: [ |
331 | { | 333 | { |
332 | model: Account['sequelize'].models.AccountFollow, | 334 | model: Account['sequelize'].models.AccountFollow, |
335 | required: true, | ||
336 | as: 'followers', | ||
333 | where: { | 337 | where: { |
334 | targetAccountId: this.id | 338 | targetAccountId: this.id |
335 | } | 339 | } |
@@ -387,7 +391,7 @@ listFollowingForApi = function (id: number, start: number, count: number, sort: | |||
387 | include: [ | 391 | include: [ |
388 | { | 392 | { |
389 | model: Account['sequelize'].models.Account, | 393 | model: Account['sequelize'].models.Account, |
390 | as: 'following', | 394 | as: 'accountFollowing', |
391 | required: true, | 395 | required: true, |
392 | include: [ Account['sequelize'].models.Pod ] | 396 | include: [ Account['sequelize'].models.Pod ] |
393 | } | 397 | } |
@@ -418,7 +422,7 @@ listFollowersForApi = function (id: number, start: number, count: number, sort: | |||
418 | include: [ | 422 | include: [ |
419 | { | 423 | { |
420 | model: Account['sequelize'].models.Account, | 424 | model: Account['sequelize'].models.Account, |
421 | as: 'followers', | 425 | as: 'accountFollowers', |
422 | required: true, | 426 | required: true, |
423 | include: [ Account['sequelize'].models.Pod ] | 427 | include: [ Account['sequelize'].models.Pod ] |
424 | } | 428 | } |
@@ -439,7 +443,7 @@ loadApplication = function () { | |||
439 | return Account.findOne({ | 443 | return Account.findOne({ |
440 | include: [ | 444 | include: [ |
441 | { | 445 | { |
442 | model: Account['sequelize'].model.Application, | 446 | model: Account['sequelize'].models.Application, |
443 | required: true | 447 | required: true |
444 | } | 448 | } |
445 | ] | 449 | ] |
@@ -460,17 +464,37 @@ loadByUUID = function (uuid: string) { | |||
460 | return Account.findOne(query) | 464 | return Account.findOne(query) |
461 | } | 465 | } |
462 | 466 | ||
463 | loadLocalAccountByNameAndPod = function (name: string, host: string) { | 467 | loadLocalByName = function (name: string) { |
464 | const query: Sequelize.FindOptions<AccountAttributes> = { | 468 | const query: Sequelize.FindOptions<AccountAttributes> = { |
465 | where: { | 469 | where: { |
466 | name, | 470 | name, |
467 | userId: { | 471 | [Sequelize.Op.or]: [ |
468 | [Sequelize.Op.ne]: null | 472 | { |
469 | } | 473 | userId: { |
474 | [Sequelize.Op.ne]: null | ||
475 | } | ||
476 | }, | ||
477 | { | ||
478 | applicationId: { | ||
479 | [Sequelize.Op.ne]: null | ||
480 | } | ||
481 | } | ||
482 | ] | ||
483 | } | ||
484 | } | ||
485 | |||
486 | return Account.findOne(query) | ||
487 | } | ||
488 | |||
489 | loadByNameAndHost = function (name: string, host: string) { | ||
490 | const query: Sequelize.FindOptions<AccountAttributes> = { | ||
491 | where: { | ||
492 | name | ||
470 | }, | 493 | }, |
471 | include: [ | 494 | include: [ |
472 | { | 495 | { |
473 | model: Account['sequelize'].models.Pod, | 496 | model: Account['sequelize'].models.Pod, |
497 | required: true, | ||
474 | where: { | 498 | where: { |
475 | host | 499 | host |
476 | } | 500 | } |