Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Updating Things and Channels Service #9

Merged
merged 17 commits into from
Apr 5, 2024

Conversation

wambui-pixel
Copy link
Contributor

@wambui-pixel wambui-pixel commented Mar 28, 2024

What does this do?

Updating Things .ts

Which issue(s) does this PR fix/relate to? NOISSUE

Resolves #15 and #17

List any changes that modify/break current functionality

Migrating things.js to things.ts

Have you included tests for your changes?

NO

Did you document any new/modified functionality?

NO

Notes

@wambui-pixel wambui-pixel marked this pull request as ready for review April 3, 2024 12:59
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/things.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
src/channels.ts Outdated Show resolved Hide resolved
examples/things.ts Outdated Show resolved Hide resolved
examples/things.ts Show resolved Hide resolved
@wambui-pixel wambui-pixel changed the title NOISSUE - Updating Things.ts NOISSUE - Updating Things and Channels Service Apr 4, 2024
src/users.ts Outdated Show resolved Hide resolved
src/sdk.ts Outdated
import Things from './things'
// import Groups from "./groups";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove all the commented out code.

src/defs.ts Outdated
@@ -57,9 +55,14 @@ export interface GroupsPage {
export interface Channel {
id?: string
name?: string
parent_id?: string
credentials?: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a channel does not have credentials.
Channel struct looks like this:

type Channel struct {
	ID          string     `json:"id,omitempty"`
	DomainID    string     `json:"domain_id,omitempty"`
	ParentID    string     `json:"parent_id,omitempty"`
	Name        string     `json:"name,omitempty"`
	Description string     `json:"description,omitempty"`
	Metadata    Metadata   `json:"metadata,omitempty"`
	Level       int        `json:"level,omitempty"`
	Path        string     `json:"path,omitempty"`
	Children    []*Channel `json:"children,omitempty"`
	CreatedAt   time.Time  `json:"created_at,omitempty"`
	UpdatedAt   time.Time  `json:"updated_at,omitempty"`
	Status      string     `json:"status,omitempty"`
	Permissions []string   `json:"permissions,omitempty"`
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer to the go sdk for these items

src/defs.ts Outdated
@@ -34,6 +29,9 @@ export interface Thing {
owner?: string
metadata?: Record<string, any>
status?: string
createdAt?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use snake case for these

src/defs.ts Outdated
@@ -18,14 +18,9 @@ export interface UsersPage {
page: PageRes
}

export interface PageRes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you deleting this interface?

src/channels.ts Outdated
*
*/
const options: RequestInit = {
method: 'post',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the method names in capital for all

Suggested change
method: 'post',
method: 'POST,

src/channels.ts Outdated
'Content-Type': this.contentType,
Authorization: `Bearer ${token}`
},
body: JSON.stringify(payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body: JSON.stringify(payload)
body: JSON.stringify({ subject: thingId, object: channelId })

@wambui-pixel wambui-pixel force-pushed the thingsupdate branch 3 times, most recently from 4442172 to 2edec88 Compare April 5, 2024 11:04
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
Signed-off-by: wambuipixel <[email protected]>
const token = '<token>'

mySdk.channels
.CreateChannel({ name: '<channelId>' }, token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.CreateChannel({ name: '<channelId>' }, token)
.CreateChannel({ name: '<channelName>' }, token)

.AddUserToChannel(
'<channelId>',
[
'<thingId>', '<thingId>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'<thingId>', '<thingId>'
'<userId>', '<userId>'

.RemoveUserFromChannel(
'<channelId>',
[
'<thingId>', '<thingId>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'<thingId>', '<thingId>'
'<userId>', '<userId>'

src/channels.ts Outdated
'Content-Type': this.contentType,
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ subject: thingId, object: channelId })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body: JSON.stringify({ subject: thingId, object: channelId })
body: JSON.stringify({ thing_id: thingId, channel_id: channelId })

src/channels.ts Outdated
'Content-Type': this.contentType,
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ subject: thingId, object: channelId })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body: JSON.stringify({ subject: thingId, object: channelId })
body: JSON.stringify({ thing_id: thingId, channel_id: channelId })

src/channels.ts Outdated
const errorRes = await response.json()
throw this.channelError.HandleError(errorRes.error, response.status)
}
const channelData: Channel = await response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const channelData: Channel = await response.json()
const updatedChannel: Channel = await response.json()

src/channels.ts Outdated
const errorRes = await response.json()
throw this.channelError.HandleError(errorRes.error, response.status)
}
const channelsData: ChannelsPage = await response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const channelsData: ChannelsPage = await response.json()
const channels: ChannelsPage = await response.json()

src/channels.ts Outdated
const errorRes = await response.json()
throw this.channelError.HandleError(errorRes.error, response.status)
}
const channelData: ChannelsPage = await response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const channelData: ChannelsPage = await response.json()
const channels: ChannelsPage = await response.json()

src/channels.ts Outdated
const errorRes = await response.json()
throw this.channelError.HandleError(errorRes.error, response.status)
}
const channelData: Channel = await response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const channelData: Channel = await response.json()
const channel: Channel = await response.json()

src/channels.ts Outdated
const errorRes = await response.json()
throw this.channelError.HandleError(errorRes.error, response.status)
}
const channelData: Channel = await response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const channelData: Channel = await response.json()
const newChannel: Channel = await response.json()

Copy link
Contributor

@ianmuchyri ianmuchyri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dborovcanin dborovcanin merged commit 6b1d4b7 into absmach:main Apr 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update JS SDK for Things
4 participants