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
d53d45f7
Commit
d53d45f7
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
c6ea5419
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/server/api/endpoints/notes/create.ts
+30
-9
30 additions, 9 deletions
src/server/api/endpoints/notes/create.ts
src/server/api/get-params.ts
+30
-0
30 additions, 0 deletions
src/server/api/get-params.ts
with
60 additions
and
9 deletions
src/server/api/endpoints/notes/create.ts
+
30
−
9
View file @
d53d45f7
...
...
@@ -4,22 +4,43 @@ import User, { ILocalUser, IUser } from '../../../../models/user';
import
DriveFile
from
'
../../../../models/drive-file
'
;
import
create
from
'
../../../../services/note/create
'
;
import
{
IApp
}
from
'
../../../../models/app
'
;
import
getParams
from
'
../../get-params
'
;
export
const
meta
=
{
params
:
{
visibility
:
{
def
:
$
.
str
.
optional
().
or
([
'
public
'
,
'
home
'
,
'
followers
'
,
'
specified
'
,
'
private
'
]),
default
:
'
public
'
,
desc
:
{
ja
:
'
投稿の公開範囲
'
}
},
visibleUserIds
:
{
def
:
$
.
arr
(
$
.
type
(
ID
)).
optional
().
unique
().
min
(
1
),
desc
:
{
ja
:
'
(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー
'
}
},
text
:
{
def
:
$
.
str
.
optional
().
nullable
().
pipe
(
isValidText
),
default
:
null
,
desc
:
{
ja
:
'
投稿内容
'
}
},
}
};
/**
* Create a note
*/
module
.
exports
=
(
params
:
any
,
user
:
ILocalUser
,
app
:
IApp
)
=>
new
Promise
(
async
(
res
,
rej
)
=>
{
// Get 'visibility' parameter
const
[
visibility
=
'
public
'
,
visibilityErr
]
=
$
.
str
.
optional
().
or
([
'
public
'
,
'
home
'
,
'
followers
'
,
'
specified
'
,
'
private
'
]).
get
(
params
.
visibility
);
if
(
visibilityErr
)
return
rej
(
'
invalid visibility
'
);
// Get 'visibleUserIds' parameter
const
[
visibleUserIds
,
visibleUserIdsErr
]
=
$
.
arr
(
$
.
type
(
ID
)).
optional
().
unique
().
min
(
1
).
get
(
params
.
visibleUserIds
);
if
(
visibleUserIdsErr
)
return
rej
(
'
invalid visibleUserIds
'
);
const
[
ps
,
psErr
]
=
getParams
(
meta
,
params
);
if
(
psErr
)
return
rej
(
psErr
);
let
visibleUsers
:
IUser
[]
=
[];
if
(
visibleUserIds
!==
undefined
)
{
visibleUsers
=
await
Promise
.
all
(
visibleUserIds
.
map
(
id
=>
User
.
findOne
({
if
(
ps
.
visibleUserIds
!==
undefined
)
{
visibleUsers
=
await
Promise
.
all
(
ps
.
visibleUserIds
.
map
(
id
=>
User
.
findOne
({
_id
:
id
})));
}
...
...
This diff is collapsed.
Click to expand it.
src/server/api/get-params.ts
0 → 100644
+
30
−
0
View file @
d53d45f7
import
{
Query
}
from
'
cafy
'
;
type
Defs
=
{
params
:
{[
key
:
string
]:
{
def
:
Query
<
any
>
;
default
?:
any
;
}}
};
export
default
function
<
T
extends
Defs
>
(
defs
:
T
,
params
:
any
):
[{
[
P
in
keyof
T
[
'
params
'
]]:
ReturnType
<
T
[
'
params
'
][
P
][
'
def
'
][
'
get
'
]
>
[
0
];
},
Error
]
{
const
x
:
any
=
{};
let
err
:
Error
=
null
;
Object
.
keys
(
defs
.
params
).
some
(
k
=>
{
const
[
v
,
e
]
=
defs
.
params
[
k
].
def
.
get
(
params
[
k
]);
if
(
e
)
{
err
=
e
;
return
true
;
}
else
{
if
(
v
===
undefined
&&
defs
.
params
[
k
].
default
)
{
x
[
k
]
=
defs
.
params
[
k
].
default
;
}
else
{
x
[
k
]
=
v
;
}
return
false
;
}
});
return
[
x
,
err
];
}
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