@@ -21,6 +21,7 @@ import { UserGrpcClient } from '../infrastructure/grpc/user-grpc.client';
2121import type { UserInfo } from '../infrastructure/grpc/user-grpc.client' ;
2222import { CreateCardsetRequest } from './dto/request/create-cardset.request' ;
2323import { UpdateCardsetRequest } from './dto/request/update-cardset.request' ;
24+ import { CollaborationUseCase } from '../../collaboration/application/collaboration.use-case' ;
2425
2526@Injectable ( )
2627export class CardsetUseCase {
@@ -39,6 +40,7 @@ export class CardsetUseCase {
3940 private readonly dataSource : DataSource ,
4041 @Inject ( CARDSET_METADATA_REPOSITORY )
4142 private readonly metadataRepository : ICardSetMetadataRepository ,
43+ private readonly collaborationUseCase : CollaborationUseCase ,
4244 ) { }
4345
4446 private async checkIsManager (
@@ -58,7 +60,6 @@ export class CardsetUseCase {
5860 async create ( userId : number , dto : CreateCardsetRequest ) : Promise < Cardset > {
5961 await this . groupGrpcClient . checkUserInGroup ( dto . groupId , userId ) ;
6062
61- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6263 const additionalManagerIds : number [ ] = dto . managerIds ?? [ ] ;
6364 for ( const managerId of additionalManagerIds ) {
6465 await this . groupGrpcClient . checkUserInGroup ( dto . groupId , managerId ) ;
@@ -110,11 +111,11 @@ export class CardsetUseCase {
110111 cardSetIds : number [ ] ,
111112 ) : Promise < Map < number , UserInfo [ ] > > {
112113 if ( cardSetIds . length === 0 || this . skipUserGrpc ) return new Map ( ) ;
113- /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
114+
114115 const managers : CardsetManager [ ] =
115116 await this . cardsetManagerRepository . findByCardSetIds ( cardSetIds ) ;
116117 const userIds : number [ ] = [ ...new Set ( managers . map ( ( m ) => m . userId ) ) ] ;
117- /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
118+
118119 const users = await this . userGrpcClient . getUsersByIds ( userIds ) ;
119120 const userMap = new Map ( users . map ( ( u ) => [ Number ( u . id ) , u ] ) ) ;
120121 const result = new Map < number , UserInfo [ ] > ( ) ;
@@ -249,11 +250,11 @@ export class CardsetUseCase {
249250 } [ ]
250251 > {
251252 await this . groupGrpcClient . checkUserInGroup ( groupId , userId ) ;
252- /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
253+
253254 const cardsets : Cardset [ ] =
254255 await this . cardsetRepository . findByGroupId ( groupId ) ;
255256 const ids : number [ ] = cardsets . map ( ( c ) => c . id ) ;
256- /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
257+
257258 const [ metadataMap , likedMap , bookmarkedMap , managersMap ] =
258259 await Promise . all ( [
259260 this . metadataRepository . findByCardSetIds ( ids ) ,
@@ -308,7 +309,6 @@ export class CardsetUseCase {
308309
309310 return this . dataSource . transaction ( async ( manager ) => {
310311 if ( dto . managerIds !== undefined ) {
311- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
312312 const newManagerIds : number [ ] = dto . managerIds ;
313313 for ( const managerId of newManagerIds ) {
314314 await this . groupGrpcClient . checkUserInGroup (
@@ -404,4 +404,15 @@ export class CardsetUseCase {
404404 return this . cardsetRepository . update ( id , updatedCardset ) ;
405405 } ) ;
406406 }
407+
408+ async saveCards ( cardSetId : number , userId : number ) : Promise < void > {
409+ await this . checkIsManager ( cardSetId , userId ) ;
410+ await this . collaborationUseCase . saveCardsetContent ( cardSetId ) ;
411+ }
412+
413+ async findCardsFromYjs (
414+ cardSetId : number ,
415+ ) : Promise < { id : string ; question : string ; answer : string } [ ] > {
416+ return this . collaborationUseCase . getCards ( cardSetId ) ;
417+ }
407418}
0 commit comments