@@ -35,6 +35,7 @@ export class AccountService {
3535 request : Request ,
3636 currentInfo : ICurrentUserType
3737 ) : Promise < string > {
38+ console . log ( request ) ;
3839 // 1.判断当前商户下是否已经存在该账号
3940 const accountEntity : Pick < AccountEntity , 'id' > | null = await this . accountRepository . findOne ( {
4041 where : { username : req . username , tenantId : currentInfo . tenantId } ,
@@ -71,7 +72,7 @@ export class AccountService {
7172 * @return {* }
7273 */
7374 async deleteAccountByIdApi ( id : number , currentUser : ICurrentUserType ) : Promise < string > {
74- const { accountId } = currentUser ;
75+ const { id : accountId } = currentUser ;
7576 // TODO 判断不能删除自己及下面有账号的
7677 if ( Object . is ( id , accountId ) ) {
7778 throw new HttpException ( '自己不能删除自己' , HttpStatus . OK ) ;
@@ -105,7 +106,11 @@ export class AccountService {
105106 * @param {number } id
106107 * @return {* }
107108 */
108- async modifyAccountStatusByIdApi ( id : number ) : Promise < string > {
109+ async modifyAccountStatusByIdApi ( id : number , currentUser : ICurrentUserType ) : Promise < string > {
110+ const { id : accountId } = currentUser ;
111+ if ( Object . is ( id , accountId ) ) {
112+ throw new HttpException ( '自己不能修改自己' , HttpStatus . OK ) ;
113+ }
109114 const accountEntity : Pick < AccountEntity , 'status' > | null =
110115 await this . accountRepository . findOne ( {
111116 where : { id } ,
@@ -134,6 +139,14 @@ export class AccountService {
134139 * @return {* }
135140 */
136141 async modifyAccountByIdApi ( id : number , req : AccountDto ) : Promise < string > {
142+ // 判断当前的用户名之前是否有
143+ const accountEntity : Pick < AccountEntity , 'id' > | null = await this . accountRepository . findOne ( {
144+ where : { username : req . username } ,
145+ select : [ 'id' ] ,
146+ } ) ;
147+ if ( accountEntity && accountEntity . id != id ) {
148+ throw new HttpException ( `[${ req . username } ]可能已经存在` , HttpStatus . OK ) ;
149+ }
137150 const { affected } = await this . accountRepository . update ( id , req ) ;
138151 if ( affected ) {
139152 return '修改成功' ;
@@ -156,6 +169,7 @@ export class AccountService {
156169 const {
157170 status,
158171 username,
172+ tenantId : queryTenantId ,
159173 pageNumber = PageEnum . PAGE_NUMBER ,
160174 pageSize = PageEnum . PAGE_SIZE ,
161175 } = queryOption ;
@@ -172,13 +186,19 @@ export class AccountService {
172186 * 2.如果不是超管,是主账号的时候查询下面全部的账号
173187 * 3.如果都不是,只能查询账号下的数据
174188 */
175- if ( accountType == AccountTypeEnum . SUPER_ACCOUNT ) {
176- console . log ( '超管不需要' ) ;
177- } else if ( accountType == AccountTypeEnum . PRIMARY_ACCOUNT ) {
178- query . set ( 'tenantId' , Equal ( tenantId + '' ) ) ;
179- } else if ( accountType == AccountTypeEnum . NORMAL_ACCOUNT ) {
180- query . set ( 'parentId' , Equal ( accountId + '' ) ) ;
189+ if ( queryTenantId ) {
190+ query . set ( 'tenantId' , Equal ( queryTenantId + '' ) ) ;
191+ } else {
192+ if ( accountType == AccountTypeEnum . SUPER_ACCOUNT ) {
193+ console . log ( '超管不需要' ) ;
194+ } else if ( accountType == AccountTypeEnum . PRIMARY_ACCOUNT ) {
195+ query . set ( 'tenantId' , Equal ( tenantId + '' ) ) ;
196+ } else if ( accountType == AccountTypeEnum . NORMAL_ACCOUNT ) {
197+ query . set ( 'parentId' , Equal ( accountId + '' ) ) ;
198+ }
181199 }
200+
201+ console . log ( mapToObj ( query ) , '???????????????????' ) ;
182202 const total = await this . accountRepository
183203 . createQueryBuilder ( 'account' )
184204 . where ( mapToObj ( query ) )
@@ -189,7 +209,6 @@ export class AccountService {
189209 . orderBy ( { id : 'DESC' } )
190210 . offset ( ( pageNumber - 1 ) * pageSize )
191211 . limit ( pageSize )
192- . printSql ( )
193212 . getRawMany ( ) ;
194213 return {
195214 data,
@@ -222,7 +241,7 @@ export class AccountService {
222241 idList : number [ ] ,
223242 currentUser : ICurrentUserType
224243 ) : Promise < string > {
225- const { accountId } = currentUser ;
244+ const { id : accountId } = currentUser ;
226245 // TODO 判断不能删除自己及下面有账号的
227246 if ( idList . includes ( accountId ) ) {
228247 throw new HttpException ( '自己不能删除自己' , HttpStatus . OK ) ;
@@ -264,7 +283,8 @@ export class AccountService {
264283 idList : number [ ] ,
265284 currentUser : ICurrentUserType
266285 ) : Promise < string > {
267- const { accountId } = currentUser ;
286+ const { id : accountId } = currentUser ;
287+ console . log ( idList , accountId , '????==============' ) ;
268288 if ( idList . includes ( accountId ) ) {
269289 throw new HttpException ( '自己不能修改自己' , HttpStatus . OK ) ;
270290 }
@@ -319,7 +339,7 @@ export class AccountService {
319339 . addSelect ( 'account1.username' , 'parentName' )
320340 . from ( AccountEntity , 'account1' ) ,
321341 'account1' ,
322- 'account.parentId=account1.id '
342+ 'account.parentId=account1.parentId '
323343 )
324344 . leftJoinAndMapOne (
325345 'xx' ,
@@ -329,7 +349,7 @@ export class AccountService {
329349 . addSelect ( 'tenant.name' , 'tenantName' )
330350 . from ( TenantEntity , 'tenant' ) ,
331351 'tenant' ,
332- 'account.tenantId=tenant.id '
352+ 'account.tenantId=tenant.tenantId '
333353 ) ;
334354 }
335355}
0 commit comments