parent
d2a5f4c5c1
commit
df20f5063d
7 changed files with 187 additions and 18 deletions
28
src/services/register-hashtag.ts
Normal file
28
src/services/register-hashtag.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { IUser } from '../models/user';
|
||||
import Hashtag from '../models/hashtag';
|
||||
|
||||
export default async function(user: IUser, tag: string) {
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
const index = await Hashtag.findOne({ tag });
|
||||
|
||||
if (index != null) {
|
||||
// 自分が初めてこのタグを使ったなら
|
||||
if (!index.mentionedUserIds.some(id => id.equals(user._id))) {
|
||||
Hashtag.update({ tag }, {
|
||||
$push: {
|
||||
mentionedUserIds: user._id
|
||||
},
|
||||
$inc: {
|
||||
mentionedUserIdsCount: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Hashtag.insert({
|
||||
tag,
|
||||
mentionedUserIds: [user._id],
|
||||
mentionedUserIdsCount: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue