Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
41982463
Unverified
Commit
41982463
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
トランザクションを使用してアンケートレコードの挿入に失敗した場合に投稿レコードの挿入もなかったことにするように
parent
2b6389b4
No related branches found
Branches containing commit
Tags
11.0.0-beta.3
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/models/entities/note.ts
+8
-0
8 additions, 0 deletions
src/models/entities/note.ts
src/models/entities/poll.ts
+8
-0
8 additions, 0 deletions
src/models/entities/poll.ts
src/services/note/create.ts
+25
-17
25 additions, 17 deletions
src/services/note/create.ts
with
41 additions
and
17 deletions
src/models/entities/note.ts
+
8
−
0
View file @
41982463
...
...
@@ -214,6 +214,14 @@ export class Note {
})
public
renoteUserHost
:
string
|
null
;
//#endregion
constructor
(
data
:
Partial
<
Note
>
)
{
if
(
data
==
null
)
return
;
for
(
const
[
k
,
v
]
of
Object
.
entries
(
data
))
{
(
this
as
any
)[
k
]
=
v
;
}
}
}
export
type
IMentionedRemoteUsers
=
{
...
...
This diff is collapsed.
Click to expand it.
src/models/entities/poll.ts
+
8
−
0
View file @
41982463
...
...
@@ -53,6 +53,14 @@ export class Poll {
})
public
userHost
:
string
|
null
;
//#endregion
constructor
(
data
:
Partial
<
Poll
>
)
{
if
(
data
==
null
)
return
;
for
(
const
[
k
,
v
]
of
Object
.
entries
(
data
))
{
(
this
as
any
)[
k
]
=
v
;
}
}
}
export
type
IPoll
=
{
...
...
This diff is collapsed.
Click to expand it.
src/services/note/create.ts
+
25
−
17
View file @
41982463
...
...
@@ -17,10 +17,10 @@ import extractMentions from '../../misc/extract-mentions';
import
extractEmojis
from
'
../../misc/extract-emojis
'
;
import
extractHashtags
from
'
../../misc/extract-hashtags
'
;
import
{
Note
}
from
'
../../models/entities/note
'
;
import
{
Mutings
,
Users
,
NoteWatchings
,
Followings
,
Notes
,
Instances
,
Polls
,
UserProfiles
}
from
'
../../models
'
;
import
{
Mutings
,
Users
,
NoteWatchings
,
Followings
,
Notes
,
Instances
,
UserProfiles
}
from
'
../../models
'
;
import
{
DriveFile
}
from
'
../../models/entities/drive-file
'
;
import
{
App
}
from
'
../../models/entities/app
'
;
import
{
Not
}
from
'
typeorm
'
;
import
{
Not
,
getConnection
}
from
'
typeorm
'
;
import
{
User
,
ILocalUser
,
IRemoteUser
}
from
'
../../models/entities/user
'
;
import
{
genId
}
from
'
../../misc/gen-id
'
;
import
{
notesChart
,
perUserNotesChart
,
activeUsersChart
,
instanceChart
}
from
'
../chart
'
;
...
...
@@ -349,7 +349,7 @@ async function publish(user: User, note: Note, reply: Note, renote: Note, noteAc
}
async
function
insertNote
(
user
:
User
,
data
:
Option
,
tags
:
string
[],
emojis
:
string
[],
mentionedUsers
:
User
[])
{
const
insert
:
Partial
<
Note
>
=
{
const
insert
=
new
Note
(
{
id
:
genId
(
data
.
createdAt
),
createdAt
:
data
.
createdAt
,
fileIds
:
data
.
files
?
data
.
files
.
map
(
file
=>
file
.
id
)
:
[],
...
...
@@ -381,7 +381,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
renoteUserId
:
data
.
renote
?
data
.
renote
.
userId
:
null
,
renoteUserHost
:
data
.
renote
?
data
.
renote
.
userHost
:
null
,
userHost
:
user
.
host
,
};
}
)
;
if
(
data
.
uri
!=
null
)
insert
.
uri
=
data
.
uri
;
...
...
@@ -397,19 +397,27 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
// 投稿を作成
try
{
const
note
=
await
Notes
.
save
(
insert
);
if
(
note
.
hasPoll
)
{
await
Polls
.
save
({
noteId
:
note
.
id
,
choices
:
data
.
poll
.
choices
,
expiresAt
:
data
.
poll
.
expiresAt
,
multiple
:
data
.
poll
.
multiple
,
votes
:
new
Array
(
data
.
poll
.
choices
.
length
).
fill
(
0
),
noteVisibility
:
note
.
visibility
,
userId
:
user
.
id
,
userHost
:
user
.
host
}
as
Poll
);
let
note
:
Note
;
if
(
insert
.
hasPoll
)
{
// Start transaction
await
getConnection
().
transaction
(
async
transactionalEntityManager
=>
{
note
=
await
transactionalEntityManager
.
save
(
insert
);
const
poll
=
new
Poll
({
noteId
:
note
.
id
,
choices
:
data
.
poll
.
choices
,
expiresAt
:
data
.
poll
.
expiresAt
,
multiple
:
data
.
poll
.
multiple
,
votes
:
new
Array
(
data
.
poll
.
choices
.
length
).
fill
(
0
),
noteVisibility
:
note
.
visibility
,
userId
:
user
.
id
,
userHost
:
user
.
host
});
await
transactionalEntityManager
.
save
(
poll
);
});
}
else
{
note
=
await
Notes
.
save
(
insert
);
}
return
note
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment