Skip to content

Commit

Permalink
chore: format code with prettier (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee authored May 5, 2023
1 parent a7be755 commit bd33935
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 93 deletions.
14 changes: 11 additions & 3 deletions apps/comments-service/src/comments-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ export class CommentsController {
async getCommentById(id: string) {
return await this.commentsService.getCommentById(id);
}

@MessagePattern({ cmd: CommentsEvents.CommentCreate })
async createComment(input: { data: CommentsModel; master: boolean; importPattern: boolean }) {
async createComment(input: {
data: CommentsModel;
master: boolean;
importPattern: boolean;
}) {
if (!input.master && !input.importPattern) {
input.data.status = CommentStatus.Pending;
}
return await this.commentsService.createComment(input.data, input.master, input.importPattern);
return await this.commentsService.createComment(
input.data,
input.master,
input.importPattern,
);
}

@MessagePattern({ cmd: CommentsEvents.CommentReply })
Expand Down
8 changes: 6 additions & 2 deletions apps/comments-service/src/comments-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CommentsService {

@Inject(ServicesEnum.notification)
private readonly notification: ClientProxy,
) { }
) {}

get model() {
return this.CommentsModel;
Expand Down Expand Up @@ -73,7 +73,11 @@ export class CommentsService {
return await this.CommentsModel.findById(id);
}

async createComment(data: CommentsModel, isMaster: boolean, importPattern: boolean) {
async createComment(
data: CommentsModel,
isMaster: boolean,
importPattern: boolean,
) {
if (isMaster && !importPattern) {
data.status = CommentStatus.Approved; // 默认审核通过主人的评论
}
Expand Down
2 changes: 1 addition & 1 deletion apps/comments-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CommentsServiceModule } from './comments-service.module';

async function bootstrap() {
registerGlobal();
registerStdLogger("comments");
registerStdLogger('comments');

const argv = BasicCommer.parse().opts();
readEnv(argv, argv.config);
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { MigrateModule } from './modules/migrate/migrate.module';
{
name: ServicesEnum.custom,
...REDIS_TRANSPORTER,
}
},
]),
MigrateModule,
],
Expand Down
4 changes: 3 additions & 1 deletion apps/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export async function bootstrap() {
consola.success(
`[${prefix + pid}] 服务器正在监听: ${listening_ip}:${PORT}`,
);
consola.success(`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`);
consola.success(
`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`,
);
Logger.log(
`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`,
);
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { registerStdLogger } from '~/shared/global/consola.global';
async function main() {
register();
mkBasedirs();
registerStdLogger("core")
registerStdLogger('core');
const [{ bootstrap }] = await Promise.all([import('./bootstrap')]);
bootstrap();
}
Expand Down
58 changes: 28 additions & 30 deletions apps/core/src/modules/category/category.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,27 @@ import { transportReqToMicroservice } from '~/shared/microservice.transporter';
export class CategoryController {
constructor(
@Inject(ServicesEnum.category) private readonly category: ClientProxy,
) { }
) {}

@Get('/ping')
@ApiOperation({ summary: '检测服务是否在线' })
async ping() {
return transportReqToMicroservice<"pong">(this.category, CategoryEvents.Ping, {});
return transportReqToMicroservice<'pong'>(
this.category,
CategoryEvents.Ping,
{},
);
}

@Get('/')
@ApiOperation({ summary: '多分类查询、分类列表' })
async getCategories(@Query() query: MultiCategoriesQueryDto) {
return transportReqToMicroservice<any[] | {
entries: Object;
}>(
this.category,
CategoryEvents.CategoryGetAll,
query,
);
return transportReqToMicroservice<
| any[]
| {
entries: Object;
}
>(this.category, CategoryEvents.CategoryGetAll, query);
}

@Get('/:query')
Expand All @@ -87,22 +90,21 @@ export class CategoryController {
@Param() { query }: SlugorIdDto,
@Query() { tag }: MultiQueryTagAndCategoryDto, // 如果这个是标签,则tag为true,如果是分类,则tag为分类id
) {
return transportReqToMicroservice<{
isTag: boolean;
data: {
name: string;
children: PostModel[] | null;
};
} | {
data: {
children: PostModel[]
};
isTag: boolean;
}>(
this.category,
CategoryEvents.CategoryGet,
{ _query: query, _tag: tag },
);
return transportReqToMicroservice<
| {
isTag: boolean;
data: {
name: string;
children: PostModel[] | null;
};
}
| {
data: {
children: PostModel[];
};
isTag: boolean;
}
>(this.category, CategoryEvents.CategoryGet, { _query: query, _tag: tag });
}

@Post('/')
Expand All @@ -123,11 +125,7 @@ export class CategoryController {
async merge(@Body() body: { type: CategoryType; from: string; to: string }) {
return transportReqToMicroservice<{
message: string;
}>(
this.category,
CategoryEvents.CategoryMerge,
body,
);
}>(this.category, CategoryEvents.CategoryMerge, body);
}

@Put('/:id')
Expand Down
8 changes: 4 additions & 4 deletions apps/core/src/modules/comments/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class CommentsController {
);
}

@Get("/:id")
@ApiOperation({ summary: "根据 ID 获取评论" })
async getCommentById(@Param("id") id: string) {
@Get('/:id')
@ApiOperation({ summary: '根据 ID 获取评论' })
async getCommentById(@Param('id') id: string) {
return transportReqToMicroservice(
this.comments,
CommentsEvents.CommentGetById,
id
id,
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/friends/friends.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class FriendsController {
this.friends,
FriendsEvents.FriendsGetAllByMaster,
{
status
status,
},
);
}
Expand Down
12 changes: 5 additions & 7 deletions apps/core/src/modules/migrate/migrate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import { ApiName } from '~/shared/common/decorator/openapi.decorator';
@Controller('migrate')
@ApiName
export class MigrateController {
constructor(
private readonly migrateService: MigrateService,
){}
constructor(private readonly migrateService: MigrateService) {}

@Post("import")
@Post('import')
// @Auth()
@ApiOperation({ summary: "使用 JSON 导入数据"})
@ApiOperation({ summary: '使用 JSON 导入数据' })
async import(@Body() body: MigrateData) {
return await this.migrateService.import(body);
}

@Get("export")
@Get('export')
// @Auth()
@ApiOperation({ summary: "导出数据为 JSON"})
@ApiOperation({ summary: '导出数据为 JSON' })
async export() {
return await this.migrateService.export();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/migrate/migrate.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ const registers = Object.values(services).map((name) => ({
@Module({
imports: [ClientsModule.register(registers)],
controllers: [MigrateController],
providers: [MigrateService]
providers: [MigrateService],
})
export class MigrateModule {}
16 changes: 11 additions & 5 deletions apps/friends-service/src/friends-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ export class FriendsService {

@Inject(ServicesEnum.notification)
private readonly notification: ClientProxy,
) { }
) {}

public get model() {
return this.friendsModel;
}

private throwInvalidTokenException(): never {
throw new UnauthorizedRpcExcption(ExceptionMessage.FriendLinkTokenIsInvalid);
throw new UnauthorizedRpcExcption(
ExceptionMessage.FriendLinkTokenIsInvalid,
);
}

private throwNotFoundException(): never {
Expand Down Expand Up @@ -166,7 +168,8 @@ export class FriendsService {
friend.autoCheck = await this.autoCheck(input.data.link);
await friend.save();
Logger.warn(
`${friend.name} 申请友链 - 互链检测: ${friend.autoCheck ? '通过' : '未通过'
`${friend.name} 申请友链 - 互链检测: ${
friend.autoCheck ? '通过' : '未通过'
}`,
FriendsService.name,
);
Expand Down Expand Up @@ -218,7 +221,8 @@ export class FriendsService {
friend.autoCheck = await this.autoCheck(data.link); // 重新检测
await friend.save();
Logger.warn(
`${friend.name} 申请友链 - 互链检测: ${friend.autoCheck ? '通过' : '未通过'
`${friend.name} 申请友链 - 互链检测: ${
friend.autoCheck ? '通过' : '未通过'
}`,
FriendsService.name,
);
Expand Down Expand Up @@ -354,7 +358,9 @@ export class FriendsService {
);
return '';
});
if (!xml) { continue; }
if (!xml) {
continue;
}
const feed = FeedParser(xml, friend.feedType);
if (!feed) {
Logger.warn(
Expand Down
2 changes: 1 addition & 1 deletion apps/friends-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FriendsServiceModule } from './friends-service.module';

async function bootstrap() {
registerGlobal();
registerStdLogger("friends");
registerStdLogger('friends');

const argv = BasicCommer.parse().opts();
readEnv(argv, argv.config);
Expand Down
2 changes: 1 addition & 1 deletion apps/notification-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NotificationServiceModule } from './notification-service.module';

async function bootstrap() {
registerGlobal();
registerStdLogger("notification");
registerStdLogger('notification');

const argv = BasicCommer.parse().opts();
readEnv(argv, argv.config);
Expand Down
2 changes: 1 addition & 1 deletion apps/page-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PageServiceModule } from './page-service.module';

async function bootstrap() {
registerGlobal();
registerStdLogger("page");
registerStdLogger('page');

const argv = BasicCommer.parse().opts();
readEnv(argv, argv.config);
Expand Down
18 changes: 10 additions & 8 deletions apps/page-service/src/page-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class PageService {

@Inject(ServicesEnum.notification)
private readonly notification: ClientProxy,
) { }
) {}

public get model() {
return this.pageModel;
Expand Down Expand Up @@ -84,13 +84,15 @@ export class PageService {
}

public async create(data: PageModel) {
const res = await this.model.create({
...data,
slug: slugify(data.slug!),
created: new Date(),
}).catch((err) => {
throw new BadRequestRpcExcption(err.message)
})
const res = await this.model
.create({
...data,
slug: slugify(data.slug!),
created: new Date(),
})
.catch((err) => {
throw new BadRequestRpcExcption(err.message);
});
this.notification.emit(NotificationEvents.SystemPageCreate, res);
return res;
}
Expand Down
14 changes: 7 additions & 7 deletions apps/page-service/src/post-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PostService {

@Inject(ServicesEnum.notification)
private readonly notification: ClientProxy,
) { }
) {}

get model() {
return this.postModel;
Expand Down Expand Up @@ -105,13 +105,13 @@ export class PostService {
{
$sort: sortBy
? {
[sortBy]: sortOrder as any,
}
[sortBy]: sortOrder as any,
}
: {
sortField: -1, // sort by our computed field
pin: -1,
created: -1, // and then by the "created" field
},
sortField: -1, // sort by our computed field
pin: -1,
created: -1, // and then by the "created" field
},
},
{
$project: {
Expand Down
6 changes: 3 additions & 3 deletions apps/store-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { StoreServiceModule } from './store-service.module';

async function bootstrap() {
registerGlobal();
registerStdLogger("store");
registerStdLogger('store');
mkStoreDir();

const argv = BasicCommer.parse().opts();
Expand All @@ -29,7 +29,7 @@ async function bootstrap() {
},
);
app.listen().then(() => {
Logger.log(`>> StoreService 正在工作... <<`)
})
Logger.log(`>> StoreService 正在工作... <<`);
});
}
bootstrap();
1 change: 0 additions & 1 deletion apps/store-service/src/store-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ export class StoreServiceController {
async storeFileMkdir(path: string) {
return await this.storeServiceService.mkdir(path);
}

}
Loading

0 comments on commit bd33935

Please sign in to comment.