Skip to content

Commit

Permalink
refactor(server): add user infomation to function template(#1395)
Browse files Browse the repository at this point in the history
* refactor(server): add template user infomation
  • Loading branch information
HUAHUAI23 committed Jul 13, 2023
1 parent 7b792b6 commit fe06872
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/src/function-template/dto/function-templates.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class FunctionTemplateItemSource {
code: string
}

class UserInfo {
@ApiPropertyOptional()
username?: string
@ApiPropertyOptional()
email?: string
}

class FunctionTemplateItems {
@ApiProperty({ type: String })
_id?: ObjectId
Expand Down Expand Up @@ -70,6 +77,9 @@ export class FunctionTemplatesDto {

@ApiPropertyOptional({ type: [FunctionTemplateItems] })
items: FunctionTemplateItems[]

@ApiPropertyOptional({ type: UserInfo })
user?: UserInfo
}

export class GetMyStaredFunctionTemplatesDto {
Expand Down
20 changes: 20 additions & 0 deletions server/src/function-template/function-template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DependencyService } from 'src/dependency/dependency.service'
import { ApplicationService } from '../application/application.service'
import { ApplicationConfigurationService } from 'src/application/configuration.service'
import { FunctionService } from 'src/function/function.service'
import { User } from 'src/user/entities/user'

interface FindFunctionTemplatesParams {
asc: number
Expand Down Expand Up @@ -1613,6 +1614,25 @@ export class FunctionTemplateService {
const res = await this.db
.collection<FunctionTemplate>('FunctionTemplate')
.findOne({ _id: templateId })

const user = await this.db.collection<User>('User').findOne({
_id: res.uid,
})

if (user.phone && user.username) {
if (user.phone == user.username) {
user.username =
user.username.slice(0, 3) +
'x'.repeat(user.username.length - 6) +
user.username.slice(-3)
}
}

res['user'] = {
username: user?.username,
email: user?.email,
}

return res
}

Expand Down

0 comments on commit fe06872

Please sign in to comment.