MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / handleUser

Function handleUser

packages/integration-linear/src/inbound.ts:159–196  ·  view source on GitHub ↗
(
  channel: { id: string; accountId: string },
  userId: string
)

Source from the content-addressed store, hash-verified

157}
158
159async function handleUser(
160 channel: { id: string; accountId: string },
161 userId: string
162) {
163 let user = await linenSdk
164 .findUser({
165 accountsId: channel.accountId,
166 externalUserId: userId,
167 })
168 .catch(console.error);
169 if (!user) {
170 // create user
171 const integration = await linenSdk.getChannelIntegration({
172 channelId: channel.id,
173 type: channelsIntegrationType.LINEAR,
174 });
175 if (!integration) {
176 throw new Error('integration not found');
177 }
178 const newUser = await fetchUser({
179 accessToken: integration.data.access_token,
180 userId: userId,
181 });
182 if (!newUser) {
183 throw new Error('user not found');
184 }
185 user = await linenSdk.findOrCreateUser({
186 accountsId: channel.accountId,
187 externalUserId: userId,
188 displayName: newUser.displayName,
189 profileImageUrl: newUser.avatarUrl,
190 });
191 if (!user) {
192 throw new Error('user not found');
193 }
194 }
195 return user;
196}

Callers 1

inbound.tsFile · 0.70

Calls 4

fetchUserFunction · 0.90
findUserMethod · 0.80
findOrCreateUserMethod · 0.80
getChannelIntegrationMethod · 0.45

Tested by

no test coverage detected