Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Sep 6, 2022
1 parent 74f2e76 commit 26cdacb
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
"tsc-alias": "1.7.0",
"tsconfig-paths": "4.1.0",
"twemoji-parser": "14.0.0",
"typeorm": "0.3.8",
"typedi": "0.10.0",
"typeorm": "0.3.9",
"ulid": "2.3.0",
"unzipper": "0.10.11",
"uuid": "8.3.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ms from 'ms';
import { In } from 'typeorm';
import create from '@/services/note/create.js';
import { User } from '@/models/entities/user.js';
import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { Note } from '@/models/entities/note.js';
import { Channel } from '@/models/entities/channel.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { noteService } from '@/services/index.js';
import { noteVisibilities } from '../../../../types.js';
import { ApiError } from '../../error.js';
import define from '../../define.js';
Expand Down Expand Up @@ -248,7 +248,7 @@ export default define(meta, paramDef, async (ps, user) => {
}

// 投稿を作成
const note = await create(user, {
const note = await noteService.create(user, {
createdAt: new Date(),
files: files,
poll: ps.poll ? {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Container, Service } from 'typedi';
import { Notes } from '@/models/index.js';
import { NoteService } from './noteService.js';

Container.set('notesRepository', Notes);
export const noteService = Container.get(NoteService);
26 changes: 26 additions & 0 deletions packages/backend/src/services/noteService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Container, Service, Inject } from 'typedi';
import { Notes } from '@/models/index.js';
import { User } from '@/models/entities/user.js';
import { genId } from '@/misc/gen-id.js';
import { WebhookService } from './webhookService.js';

@Service()
export class NoteService {
constructor(
@Inject('notesRepository')
public notesRepository: typeof Notes,

public webhookService: WebhookService,
) {}

public async create(user: User, data: any) {
const created = await this.notesRepository.insert({
...data,
id: genId(),
userId: user.id,
text: data.text + '!!!',
}).then(x => this.notesRepository.findOneByOrFail(x.identifiers[0]));
this.webhookService.deliver();
return created;
}
}
12 changes: 12 additions & 0 deletions packages/backend/src/services/webhookService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Container, Service } from 'typedi';

@Service()
export class WebhookService {
constructor(

) {}

public deliver() {
console.log('delivered');
}
}
13 changes: 9 additions & 4 deletions packages/backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9046,10 +9046,15 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

[email protected]:
version "0.3.8"
resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.3.8.tgz#134ab0736592da5d5ca66d4eb8cea5999e34d5f9"
integrity sha512-77PNamypfwieZlhwbUAjMudX2T+5F6JCoNR18RdKenJ5Uu+9gc9AWa1kmz/2hH84MU23lGqPCu8u2lKnlfsN2g==
[email protected]:
version "0.10.0"
resolved "https://registry.yarnpkg.com/typedi/-/typedi-0.10.0.tgz#e8f9a5ee100b84addbdfb57fe90d8d9ed2a21dea"
integrity sha512-v3UJF8xm68BBj6AF4oQML3ikrfK2c9EmZUyLOfShpJuItAqVBHWP/KtpGinkSsIiP6EZyyb6Z3NXyW9dgS9X1w==

[email protected]:
version "0.3.9"
resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.3.9.tgz#ad0f525d81c081fd11006f97030f47a55978ac81"
integrity sha512-xNcE44D4hn74n7pjuMog9hRgep+BiO3IBpjEaQZ8fb56zsDz7xHT1GAeWwmGuuU+4nDEELp2mIqgSCR+zxR7Jw==
dependencies:
"@sqltools/formatter" "^1.2.2"
app-root-path "^3.0.0"
Expand Down

0 comments on commit 26cdacb

Please sign in to comment.