-
Notifications
You must be signed in to change notification settings - Fork 3
WIP: Feat/user channel create delete #68
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many things! Really cool. Still didn't get to test it, but found a few things to comment on anyway.
All of this also assumes the R4 frontend is updated, so it doesn't try to do everything twice?
@@ -98,7 +98,7 @@ | |||
// write: only the user owner can write a channel | |||
// write: only a user with no channel can write a new one to himself | |||
".write": "auth != null && (root.child('users').child(auth.uid).child('channels').child($channelID).exists() || (!data.exists() && !root.child('users').child(auth.uid).child('channels').exists()))", | |||
".validate": "newData.hasChildren(['slug', 'title', 'created']) || !newData.exists()", | |||
".validate": "newData.hasChildren(['title']) || !newData.exists()", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe slug
was removed because it's now generated in the backend, but what about created
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should generate it in the Backend as well. My mistake!
// create new /users/:newUser | ||
let userRef = admin.database().ref(`/users/${userUid}`) | ||
userRef.set({ | ||
settings: userSettingsId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't createUserSetting
be part of this method? So you don't have to call both. Also, if you don't have a userSetting, how can you create a user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- usersettings = await createUserSettings(userId) https://github.com/internet4000/radio4000-api/pull/68/files#diff-1cca320b5f907e0ee8b85ce1f2984e4eR73
- user = await createUser(userSettings.key) https://github.com/internet4000/radio4000-api/pull/68/files#diff-1cca320b5f907e0ee8b85ce1f2984e4eR82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the firebase.function.aut.onRegister = handleUserCreate
is splitted in functions that handle small part of this process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I'm confused. So what's the steps to create a new user from a front-end perspective?
var userRef = await database.ref('/users').push()
userRef.set({someProperty: 'helloword'})
And then backend takes care of the usersetting?
let userRef = admin.database().ref(`/users/${userUid}`) | ||
return await userRef.once('value').then(dataSnapshot => { | ||
return dataSnapshot.val() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stick to either await
or then
?
let userRef = admin.database().ref(`/users/${userUid}`) | |
return await userRef.once('value').then(dataSnapshot => { | |
return dataSnapshot.val() | |
}) | |
let userRef = admin.database().ref(`/users/${userUid}`) | |
let snapshot = await userRef.once('value') | |
return snapshot.val() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, but here the second await is not needed, as everything happens sequentially in the then
console.log('channels', channels) | ||
if (!channels) { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to delete the channels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja!
functions/channel.js
Outdated
when a channel is deleted | ||
*/ | ||
|
||
const handleChannelDelete = async (change, context) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but move this method to the end of the file? So it reads create, update, delete.
functions/channel.js
Outdated
await userChannelRef.update({ | ||
slug: slugify(title) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inside R4 front-end we validate slug to make sure it's unique. Guess we need to do that here before updating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally correct! Glad you are looking at the file!
.firebaserc
Outdated
"staging": "radio4000-staging" | ||
"staging": "radio4000-staging", | ||
"dev": "radio4000-hugurp", | ||
"default": "radio4000-hugurp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is default used anywhere or can we remove?
|
||
let updates = {} | ||
Object.keys(followers).forEach(followerId => { | ||
updates[`/channels/${followerId}/favoriteChannels/${channelId}`] = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does channelId
come from?
nvm install 10.10.0 // install node 10 | ||
nvm use 10.10.0 // use node 10 | ||
npm // install npm dependencies with yarn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need 10.10.0 or just 10.x?
nvm install 10.10.0 // install node 10 | |
nvm use 10.10.0 // use node 10 | |
npm // install npm dependencies with yarn | |
nvm use 10 | |
npm install |
@@ -103,7 +104,9 @@ const handleChannelCreate = async (snapshot, context) => { | |||
// validate slug, or generate it | |||
try { | |||
await userChannelRef.update({ | |||
slug: slugify(title) | |||
slug: slugify(title), | |||
created: admin.database.ServerValue.TIMESTAMP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so nice if we don't have to deal with timestamps in the frontend
Handle:
channel.slug = slugify(channel.title)
channel.channelPublic.followers.forEach( delete favorites[channel]
channel.slug = slugify(channel.slug || channel.title)
No so easy to test functions locally, and deploy. So many google, gcloud, firebase login things, service accounts. Heavy to maintain and document, have to put CI/CD, but that as well. Having to go through the service accounts and api access interfaces, be sure that everything use the correct profiles, re-generate everything to rotate-keys...